Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fish shell completion to be compatible with macOS/BSD #63

Closed
wants to merge 8 commits into from
31 changes: 18 additions & 13 deletions vex/shell_configs/fish
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ end
function __vex_needs_virtualenv
# Return 0 if we should expect a virtualenv arg.
# This is normally if there were no positional args after 'vex'.
# But we also don't need it if we already saw --path.
# But we also don't need it if we already saw --path or --make.
set args (__vex_positional_args)
set opts (__vex_optional_args)
for opt in $opts
if [ $opt = '--path' ]
# Add 'x' as a prefix to workaround
# https://github.com/fish-shell/fish-shell/issues/5186#issuecomment-421244106
if [ x$opt = 'x--path' -o x$opt = 'x--make' -o x$opt = 'x-m' ]
return 1
end
end
Expand All @@ -39,7 +41,7 @@ end

function __vex_list_virtualenvs
# echo the names of virtualenvs available as 'vex VENVNAME'.
set dirs (find "$WORKON_HOME" -maxdepth 2 -name "bin" -type d -not -empty -printf '%h\n')
set dirs (find "$WORKON_HOME" -maxdepth 2 -name "bin" -type d -not -empty | xargs -n 1 dirname)
for NAME in $dirs
basename $NAME
end
Expand All @@ -52,30 +54,33 @@ function __vex_list_commands
if [ (count $cmd) -eq 2 -a $cmd[1] = 'vex' ]
set ve "$WORKON_HOME/$cmd[2]"
if test -f "$ve/bin"
find "$ve/bin" -maxdepth 1 -executable -printf '%f\n'
find "$ve/bin" -maxdepth 1 -executable | xargs basename
end
end
set -l ctoken (commandline -ct)
complete -C$ctoken
if not string match -- '-*' $ctoken
complete -C$ctoken
end
end

# If we source this, we want to wipe out previously defined vex completions
complete -e -c vex
complete --no-files -c vex
# Two positional arguments, a virtualenv and a command.
complete -c vex -n "__vex_needs_virtualenv" -d "Virtualenv" -f -a "(__vex_list_virtualenvs)"
complete -c vex -n "__vex_needs_virtualenv" -d "Virtualenv" -f -a "(__vex_list_virtualenvs)"
complete -c vex -n "__vex_needs_command" -d "Command from Virtualenv" -x -a "(__vex_list_commands)"
# Other options.
complete -c vex -l help -s h -n "__fish_no_arguments" -d "print help information"
complete -c vex -l path -x -a "(__fish_complete_directories)" -d "Give absolute path to virtualenv"
complete -c vex -l cwd -x -a "(__fish_complete_directories)" -d "Give directory to run in"
complete -c vex -l config -r -a "" -d "Give path to vexrc file"
complete -c vex -l shell-config -r -a "fish zsh bash" -d "print evaluable shell config"
complete -c vex -l make -n "__fish_no_arguments" -d "create named virtualenv before running"
complete -c vex -l config -r -a "(__fish_complete_path)" -d "Give path to vexrc file"
complete --no-files -c vex -l shell-config -r -a "fish zsh bash" -d "print evaluable shell config"
complete -c vex -l make -s m -n "__fish_no_arguments" -d "create named virtualenv before running"
# Options which should only be offered if user gave --make.
complete -c vex -l python -n "__fish_contains_opt make" -a PYTHON -d "specify python to use with --make"
complete -c vex -l site-packages -n "__fish_contains_opt make" -d "allow import of site packages from new virtualenv"
complete -c vex -l always-copy -n "__fish_contains_opt make" -d "copy files instead of creating symlinks when making virtualenv"
complete -c vex -l remove -s r -n "__fish_no_arguments" -d "remove named virtualenv after running"
complete -c vex -l python -n "__fish_contains_opt -s m make" -x -a "(__vex_list_commands)" -d "specify python to use with --make"
complete -c vex -l site-packages -n "__fish_contains_opt -s m make" -d "allow import of site packages from new virtualenv"
complete -c vex -l always-copy -n "__fish_contains_opt -s m make" -d "copy files instead of creating symlinks when making virtualenv"
complete -c vex -l remove -s r -n "__vex_needs_virtualenv" -d "remove named virtualenv after running"

# any switches on the end - no clear way to stop the processing!
#complete -c vex -u