From d13c6dc44168ed4c0e71497ec2bbb752600a9e53 Mon Sep 17 00:00:00 2001 From: Jun T Date: Fri, 4 Jul 2014 00:59:13 +0900 Subject: 32833: complete Python and Ruby arguments as for Perl --- Completion/Unix/Command/_python | 33 ++++++++++++++++++++++----------- Completion/Unix/Command/_ruby | 14 ++++++++++++-- 2 files changed, 34 insertions(+), 13 deletions(-) (limited to 'Completion') diff --git a/Completion/Unix/Command/_python b/Completion/Unix/Command/_python index edc49b72b..da84b30b5 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 03f4e60c7..80f92d5e1 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 -- cgit 1.4.1