@@ -44,6 +44,38 @@ _comp_cmd_python()
44
44
esac
45
45
46
46
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
+
47
79
# shellcheck disable=SC2254
48
80
case $prev in
49
81
--help | --version | -${noargopts} [? hVc])
@@ -74,19 +106,10 @@ _comp_cmd_python()
74
106
_comp_compgen -- -W " help off"
75
107
return
76
108
;;
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
- ;;
83
109
esac
84
110
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)'
90
113
else
91
114
_comp_compgen_help - <<< " $(" $1 " -h |
92
115
awk '{ sub(" \\ (-bb:" ," \n -bb " ); print }')"
0 commit comments