zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: PATCH: _perl_modules assumes it's called by perl
Date: Mon, 29 Mar 2021 15:06:44 +0000	[thread overview]
Message-ID: <20210329150644.GA30806@tarpaulin.shahaf.local2> (raw)

A couple of issues in _perl_modules.

1. The condition «[[ ${+perl} -eq 1 ]]» will always be true.

2. If called by some command other than perl, it will invoke that
command as «$foo -e 'print "@INC"'», assuming it to be a perl.  For
instance:
.
    % compdef _perl_modules git
    % git <TAB>
    unknown option: -e
    ⋮

How about the following? —

diff --git a/Completion/Unix/Type/_perl_modules b/Completion/Unix/Type/_perl_modules
index d27a7f7af..02b43366a 100644
--- a/Completion/Unix/Type/_perl_modules
+++ b/Completion/Unix/Type/_perl_modules
@@ -60,10 +60,11 @@ _perl_modules () {
     with_pod=_with_pod
   fi
 
-  local perl=${words[1]%doc} perl_modules
-  if whence $perl >/dev/null; then
+  local perl perl_modules
+  if [[ $service == (perl|perldoc) ]]; then
+    perl=${${(Q)words[1]}%doc}
     perl_modules=_${${perl//[^[:alnum:]]/_}#_}_modules$with_pod
-  elif (( ${+commands[perl]} )); then
+  elif whence perl > /dev/null; then
     perl=perl
     perl_modules=_perl_modules$with_pod
   else
@@ -81,8 +82,8 @@ _perl_modules () {
     else
       local inc libdir new_pms
 
-      if [[ ${+perl} -eq 1 ]]; then
-        inc=( $( $perl -e 'print "@INC"' ) )
+      if [[ -n $perl ]]; then
+        inc=( $( _call_program perl-inc ${(q)perl}$' -e \'print "@INC"\'' ) )
       else
         # If perl isn't there, one wonders why the user's trying to
         # complete Perl modules.  Maybe her $path is wrong?


             reply	other threads:[~2021-03-29 15:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-29 15:06 Daniel Shahaf [this message]
2021-03-29 15:16 ` Bart Schaefer
2021-03-29 15:28   ` Daniel Shahaf
2021-04-08  2:12     ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210329150644.GA30806@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).