@@ -44,6 +44,36 @@ _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+ ;;
60+ -- | -${noargopts} [cm])
61+ if (( i + 1 < cword)) ; then
62+ has_command=set
63+ fi
64+ ;;
65+ -* ) ;;
66+ * )
67+ has_command=set
68+ break
69+ ;;
70+ esac
71+ done
72+ if [[ $has_command ]]; then
73+ _comp_compgen_filedir
74+ return
75+ fi
76+
4777 # shellcheck disable=SC2254
4878 case $prev in
4979 --help | --version | -${noargopts} [? hVc])
@@ -74,19 +104,10 @@ _comp_cmd_python()
74104 _comp_compgen -- -W " help off"
75105 return
76106 ;;
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- ;;
83107 esac
84108
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)'
109+ if [[ $prev == -- || $cur != -* ]]; then
110+ _comp_compgen_filedir ' @(py?([cowz])|zip)'
90111 else
91112 _comp_compgen_help - <<< " $(" $1 " -h |
92113 awk '{ sub(" \\ (-bb:" ," \n -bb " ); print }')"
0 commit comments