11# bash completion for venv -*- shell-script -*-
22
33_venv () {
4- local cur_word prev_word _subcommands subcommands help_options
4+ local first_word second_word cur_word prev_word _subcommands subcommands help_options
5+ first_word=" ${COMP_WORDS[0]} "
6+ second_word=" ${COMP_WORDS[1]} "
57 cur_word=" ${COMP_WORDS[COMP_CWORD]} "
68 prev_word=" ${COMP_WORDS[COMP_CWORD-1]} "
79
8- _subcommands=" activate clear create deactivate delete install lock"
10+ _subcommands=" activate clear create deactivate delete install lock uninstall "
911 subcommands=( $( compgen -W " ${_subcommands} " -- " ${cur_word} " ) )
1012 help_options=( $( compgen -W " -h --help" -- " ${cur_word} " ) )
1113
12- # Generate completions for subcommand options
1314 compopt -o nosort
14- case " ${prev_word} " in
15- " venv" )
16- # If only 'venv' has been entered, generate list of subcommands and options
17- COMPREPLY+=( ${subcommands[*]} )
18- COMPREPLY+=( ${help_options[*]} )
15+ if [ " ${first_word} " != " venv" ]; then
16+ return
17+ fi
1918
20- local version_options
21- version_options=( $( compgen -W " -V --version" -- " ${cur_word} " ) )
22- COMPREPLY+=( ${version_options[*]} )
23- ;;
19+ if [ " ${prev_word} " == " venv" ]; then
20+ # If only 'venv' has been entered, generate list of subcommands and options
21+ COMPREPLY+=( ${subcommands[*]} )
22+ COMPREPLY+=( ${help_options[*]} )
23+
24+ local version_options
25+ version_options=( $( compgen -W " -V --version" -- " ${cur_word} " ) )
26+ COMPREPLY+=( ${version_options[*]} )
27+ return
28+ fi
29+
30+ # Generate completions for subcommand options
31+ case " ${second_word} " in
2432 " create" )
2533 # Generate list of all available python3 versions
2634
@@ -45,10 +53,30 @@ _venv() {
4553 COMPREPLY+=( $( compgen -W " -y" -- " ${cur_word} " ) )
4654 ;;
4755 " install" )
48- # Generate completions for requirement and lock file paths
49- COMPREPLY+=( $( compgen -f -X ' !(*.txt|*.lock)' -- " ${cur_word} " | sort) )
50- COMPREPLY+=( ${help_options[*]} )
51- compopt -o plusdirs +o nosort # Add directories after generated completions
56+ case " ${prev_word} " in
57+ " -r" |" --requirement" )
58+ # Generate completions for requirement and lock file paths if -r or --requirement is used
59+ COMPREPLY+=( $( compgen -f -X ' !(*.txt|*.lock)' -- " ${cur_word} " | sort) )
60+ compopt -o plusdirs +o nosort # Add directories after generated completions
61+ ;;
62+ * )
63+ COMPREPLY+=( ${help_options[*]} )
64+ COMPREPLY+=( $( compgen -W " -r --requirement -s --skip-lock --pip-args" -- " ${cur_word} " ) )
65+ ;;
66+ esac
67+ ;;
68+ " uninstall" )
69+ case " ${prev_word} " in
70+ " -r" |" --requirement" )
71+ # Generate completions for requirements file paths if -r or --requirement is used
72+ COMPREPLY+=( $( compgen -f -X ' !(*.txt)' -- " ${cur_word} " | sort) )
73+ compopt -o plusdirs +o nosort # Add directories after generated completions
74+ ;;
75+ * )
76+ COMPREPLY+=( ${help_options[*]} )
77+ COMPREPLY+=( $( compgen -W " -r --requirement -s --skip-lock --pip-args" -- " ${cur_word} " ) )
78+ ;;
79+ esac
5280 ;;
5381 " lock" )
5482 # Generate completions for lock file paths
0 commit comments