Skip to content

Commit 0944048

Browse files
committed
fix(python): complete filenames for script arguments
1 parent 959e6f9 commit 0944048

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

completions/python

+34-11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,38 @@ _comp_cmd_python()
4444
esac
4545

4646
local noargopts='!(-*|*[cmQWX]*)'
47+
48+
# if command, module, or script is already given by [-c command | -m module
49+
# | script], complete all kind of files.
50+
local i has_command=""
51+
for ((i = 1; i < cword; i++)); do
52+
# shellcheck disable=SC2254
53+
case ${words[i]} in
54+
-${noargopts}[QWX])
55+
((i++))
56+
;;
57+
-${noargopts}[cm]?*)
58+
has_command=set
59+
break
60+
;;
61+
-- | -${noargopts}[cm])
62+
if ((i + 1 < cword)); then
63+
has_command=set
64+
break
65+
fi
66+
;;
67+
-*) ;;
68+
*)
69+
has_command=set
70+
break
71+
;;
72+
esac
73+
done
74+
if [[ $has_command ]]; then
75+
_comp_compgen_filedir
76+
return
77+
fi
78+
4779
# shellcheck disable=SC2254
4880
case $prev in
4981
--help | --version | -${noargopts}[?hVc])
@@ -74,19 +106,10 @@ _comp_cmd_python()
74106
_comp_compgen -- -W "help off"
75107
return
76108
;;
77-
!(?(*/)?(micro)python*([0-9.])|?(*/)py@(py|ston)*([0-9.])|-?))
78-
if [[ $cword -lt 2 || ${words[cword - 2]} != -[QWX] ]]; then
79-
_comp_compgen_filedir
80-
return
81-
fi
82-
;;
83109
esac
84110

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

0 commit comments

Comments
 (0)