Skip to content

Commit

Permalink
fix(python): complete filenames for script arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Aug 6, 2023
1 parent 979ad22 commit 69b6030
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions completions/python
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,38 @@ _comp_cmd_python()
esac

local noargopts='!(-*|*[cmQWX]*)'

# if command, module, or script is already given by [-c command | -m module
# | script], complete all kind of files.
local i has_command=""
for ((i = 1; i < cword; i++)); do
# shellcheck disable=SC2254
case ${words[i]} in
-${noargopts}[QWX])
((i++))
;;
-${noargopts}[cm]?*)
has_command=set
break
;;
-- | -${noargopts}[cm])
if ((i + 1 < cword)); then
has_command=set
break
fi
;;
-*) ;;
*)
has_command=set
break
;;
esac
done
if [[ $has_command ]]; then
_comp_compgen_filedir
return
fi

# shellcheck disable=SC2254
case $prev in
--help | --version | -${noargopts}[?hVc])
Expand Down Expand Up @@ -74,19 +106,10 @@ _comp_cmd_python()
_comp_compgen -- -W "help off"
return
;;
!(?(*/)?(micro)python*([0-9.])|?(*/)py@(py|ston)*([0-9.])|-?))
if [[ $cword -lt 2 || ${words[cword - 2]} != -[QWX] ]]; then
_comp_compgen_filedir
return
fi
;;
esac

# if -c or -m is already given, complete all kind of files.
if [[ ${words[*]::cword} == *\ -[cm]\ * ]]; then
_comp_compgen -a filedir
elif [[ $cur != -* ]]; then
_comp_compgen -a filedir '@(py?([cowz])|zip)'
if [[ $prev == -- || $cur != -* ]]; then
_comp_compgen_filedir '@(py?([cowz])|zip)'
else
_comp_compgen_help - <<<"$("$1" -h |
awk '{ sub("\\(-bb:","\n-bb "); print }')"
Expand Down

0 comments on commit 69b6030

Please sign in to comment.