2021-04-28 14:49:35 +00:00
|
|
|
function venv -d "Manipulate Python virtual environments (venv)"
|
|
|
|
|
|
|
|
if test (count $argv) -eq 0
|
|
|
|
echo "usage: venv [list | deactivate | activate VENV]"
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if test $argv[1] = "list" -o $argv[1] = "l"
|
2021-10-13 12:07:02 +00:00
|
|
|
printf "%10s %10s %10s\n" "Name" "Version" "IPython"
|
|
|
|
for venv in (ls $WORKON_HOME)
|
|
|
|
set venv_path "$WORKON_HOME/$venv"
|
|
|
|
set venv_version ($venv_path/bin/python --version | cut -d' ' -f 2)
|
|
|
|
set venv_ipython (command -v $venv_path/bin/ipython > /dev/null && echo "yes" || echo "no")
|
|
|
|
printf "%10s %10s %10s\n" "$venv" "$venv_version" "$venv_ipython"
|
|
|
|
end
|
2021-04-28 14:49:35 +00:00
|
|
|
else if test $argv[1] = "deactivate" -o $argv[1] = "d"
|
|
|
|
type -q deactivate; and deactivate
|
|
|
|
else if test $argv[1] = "activate" -o $argv[1] = "a"
|
|
|
|
source $WORKON_HOME/{$argv[2]}/bin/activate.fish
|
2021-10-13 12:07:02 +00:00
|
|
|
else if test $argv[1] = "remove" -o $argv[1] = "r"
|
|
|
|
set venv_folder $WORKON_HOME/{$argv[2]}
|
|
|
|
if set -q VIRTUAL_ENV && test $VIRTUAL_ENV = $venv_folder
|
|
|
|
deactivate
|
|
|
|
end
|
|
|
|
rm -rf $venv_folder
|
2021-04-28 14:49:35 +00:00
|
|
|
else
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
# see http://fishshell.com/docs/current/completions.html
|
|
|
|
|
|
|
|
# disable file completions
|
|
|
|
complete -c venv -f
|
|
|
|
|
|
|
|
# subcommand completion
|
2021-10-21 08:35:56 +00:00
|
|
|
set -l commands list l deactivate d activate a remove r
|
2021-04-28 14:49:35 +00:00
|
|
|
complete -c venv -n "not __fish_seen_subcommand_from $commands" -a "$commands"
|
|
|
|
|
|
|
|
# activate completion
|
2021-10-13 12:07:02 +00:00
|
|
|
complete -c venv -n "__fish_seen_subcommand_from a" \
|
|
|
|
-a "(ls $WORKON_HOME)"
|
2021-04-28 14:49:35 +00:00
|
|
|
complete -c venv -n "__fish_seen_subcommand_from activate" \
|
|
|
|
-a "(ls $WORKON_HOME)"
|
2021-10-13 12:07:02 +00:00
|
|
|
|
|
|
|
complete -c venv -n "__fish_seen_subcommand_from r" \
|
|
|
|
-a "(ls $WORKON_HOME)"
|
|
|
|
complete -c venv -n "__fish_seen_subcommand_from remove" \
|
|
|
|
-a "(ls $WORKON_HOME)"
|