zsh-workers
 help / color / mirror / code / Atom feed
From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: [Pkg-zsh-devel] Bug#679824: zsh: Buggy perl completion with -e [origin: vincent@vinc17.net]
Date: Fri, 4 Jul 2014 00:59:13 +0900	[thread overview]
Message-ID: <9EFC1491-C1F9-407F-B0A7-BFCC51414D51@kba.biglobe.ne.jp> (raw)
In-Reply-To: <461B8CB3-4C88-42D4-987F-3A9C3846EB03@kba.biglobe.ne.jp>

2014/06/30 22:02, Jun T. <takimoto-j@kba.biglobe.ne.jp> wrote:
>    python -c '...' <TAB>
>    ruby -e '...' <TAB>
> 
> these will complete a command name, not a file name.

The following is a patch to fix this.

In the case of ruby, the current _ruby contains
  '(-)1:script file:_files'
This means all files (foo.rb, bar.py, junk.c, etc.) are
offered as Ruby scripts, but I didn't change this in the
patch. I have no experience with ruby and don't know
what most ruby users expect here.


diff --git a/Completion/Unix/Command/_python b/Completion/Unix/Command/_python
index edc49b7..da84b30 100644
--- a/Completion/Unix/Command/_python
+++ b/Completion/Unix/Command/_python
@@ -24,12 +24,12 @@ fi
 
 _arguments -C -s -S "$args[@]" \
   "-B[don't write .py\[co\] files on import]" \
-  '(1 -)-c+[program passed in as string (terminates option list)]:python command:' \
+  '(-)-c+[program passed in as string (terminates option list)]:python command:' \
   '-d[debug output from parser]' \
   '-E[ignore PYTHON* environment variables (such as PYTHONPATH)]' \
   '(1 * -)-h[display help information]' \
   '-i[inspect interactively after running script]' \
-  '(1 * -)-m[run library module as a script (terminates option list)]:module:->modules' \
+  '(-)-m[run library module as a script (terminates option list)]:module:->modules' \
   '-O[optimize generated bytecode slightly]' \
   '-OO[remove doc-strings in addition to the -O optimizations]' \
   "-s[don't add user site directory to sys.path]" \
@@ -39,16 +39,27 @@ _arguments -C -s -S "$args[@]" \
   '(1 * -)-V[display version information]' \
   '-W+[warning control]:warning filter (action\:message\:category\:module\:lineno):(default always ignore module once error)' \
   '-x[skip first line of source, allowing use of non-Unix forms of #!cmd]' \
-  '(-)1:script file:_files -g "*.py(|c|o)(-.)"' \
+  '(-)1:script_or_arg:->script_or_arg' \
   '*::script argument: _normal' && return
 
-if [[ "$state" = modules ]]; then
-  local -a modules
-  modules=(
-    ${${=${(f)"$(_call_program modules $words[1] -c \
-      'from\ pydoc\ import\ help\;\ help\(\"modules\"\)')"}[2,-3]}:#\(package\)}
-  )
-  _wanted modules expl module compadd -a modules && return
-fi
+case "$state" in
+  modules)
+    local -a modules
+    modules=(
+      ${${=${(f)"$(_call_program modules $words[1] -c \
+        'from\ pydoc\ import\ help\;\ help\(\"modules\"\)')"}[2,-3]}:#\(package\)}
+    )
+    _wanted modules expl module compadd -a modules && return
+    ;;
+  script_or_arg)
+    if [[ -n "$opt_args[(I)-(c|m)]" ]]; then
+      _description arg expl 'file'
+      _files "$expl[@]" && return
+    else
+      _description script expl 'Python script'
+      _files "$expl[@]" -g "*.py(|c|o)(-.)" && return
+    fi
+    ;;
+esac
 
 return 1
diff --git a/Completion/Unix/Command/_ruby b/Completion/Unix/Command/_ruby
index 03f4e60..80f92d5 100644
--- a/Completion/Unix/Command/_ruby
+++ b/Completion/Unix/Command/_ruby
@@ -8,7 +8,7 @@ typeset -A opt_args
 local -a args opts
 
 args=(
-  '(-)1:script file:_files'
+  '(-)1:script or argument:->script_or_arg'
   '*::script argument: _normal'
 )
 
@@ -18,7 +18,7 @@ opts=(
   '-c[check syntax only]'
   '-C+[cd to directory, before executing your script]:directory:_files -/'
   '(-d --debug)'{-d,--debug}'[set debugging flags (set $DEBUG to true)]'
-  "(1)*-e+[one line of script (several -e's allowed, omit program file)]:one line of script:"
+  "*-e+[one line of script (several -e's allowed, omit program file)]:one line of script:"
   '-F-[split() pattern for autosplit (-a)]:input field separator:'
   '-i-[edit ARGV files in place (make backup if extension supplied)]:suffix for in-place-edit mode:(.bak)'
   '*-I+[specify $LOAD_PATH directory (may be used more than once)]:library directory:_files -/'
@@ -67,6 +67,16 @@ case "$state" in
     dirs=( $(_call_program directories $cmd -e 'puts\ \$:' 2>/dev/null) ${(s.:.)opt_args[-I]} )
     _wanted libraries expl library _path_files -W dirs && ret=0
   ;;
+  script_or_arg)
+    if [[ -n "$opt_args[(I)-e]" ]]; then
+      _description arg expl 'file'
+      _files "$expl[@]" && ret=0
+    else
+      _description script expl 'Ruby script'
+      _files "$expl[@]" && ret=0
+      #_files "$expl[@]" -g "*.rb(-.)" && ret=0
+    fi
+    ;;
 esac
 
 return ret




  reply	other threads:[~2014-07-03 15:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-28 14:20 Fwd: " Axel Beckert
2014-06-30 10:58 ` Jun T.
2014-06-30 13:02   ` Jun T.
2014-07-03 15:59     ` Jun T. [this message]
2014-07-03 16:11       ` Peter Stephenson
2014-07-03 16:42         ` Bart Schaefer
2014-07-06 21:58   ` Oliver Kiddle
2014-07-23 12:01     ` takimoto-j
2014-06-30 11:45 ` Jun T.
2014-06-30 19:09   ` Peter Stephenson

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=9EFC1491-C1F9-407F-B0A7-BFCC51414D51@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --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).