From ce96d464e3e04a2fd5d2a8dc08cbd601be2e3476 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Fri, 7 Dec 2018 13:40:10 -0500 Subject: [PATCH] Add proper pyenv support to fish --- config/fish/completions/pyenv.bash | 16 +++++++++++++++ config/fish/completions/pyenv.fish | 31 +++++++++++++++--------------- config/fish/completions/pyenv.zsh | 18 +++++++++++++++++ config/fish/conf.d/pyenv.fish | 19 ------------------ config/fish/fishfile | 3 +-- config/fish/functions/pyenv.fish | 12 ------------ 6 files changed, 50 insertions(+), 49 deletions(-) create mode 100644 config/fish/completions/pyenv.bash create mode 100644 config/fish/completions/pyenv.zsh delete mode 100644 config/fish/conf.d/pyenv.fish delete mode 100644 config/fish/functions/pyenv.fish diff --git a/config/fish/completions/pyenv.bash b/config/fish/completions/pyenv.bash new file mode 100644 index 0000000..c8d8aa6 --- /dev/null +++ b/config/fish/completions/pyenv.bash @@ -0,0 +1,16 @@ +_pyenv() { + COMPREPLY=() + local word="${COMP_WORDS[COMP_CWORD]}" + + if [ "$COMP_CWORD" -eq 1 ]; then + COMPREPLY=( $(compgen -W "$(pyenv commands)" -- "$word") ) + else + local words=("${COMP_WORDS[@]}") + unset words[0] + unset words[$COMP_CWORD] + local completions=$(pyenv completions "${words[@]}") + COMPREPLY=( $(compgen -W "$completions" -- "$word") ) + fi +} + +complete -F _pyenv pyenv diff --git a/config/fish/completions/pyenv.fish b/config/fish/completions/pyenv.fish index bf59443..4d2d51d 100644 --- a/config/fish/completions/pyenv.fish +++ b/config/fish/completions/pyenv.fish @@ -1,24 +1,23 @@ function __fish_pyenv_needs_command - set cmd (commandline -opc) - if test (count $cmd) -eq 1 -a "$cmd[1]" = "pyenv" - return 0 - end - return 1 + set cmd (commandline -opc) + if [ (count $cmd) -eq 1 -a $cmd[1] = 'pyenv' ] + return 0 + end + return 1 end function __fish_pyenv_using_command - set cmd (commandline -opc) - if test (count $cmd) -gt 1 - if test "$argv[1]" = "$cmd[2]" - return 0 - end + set cmd (commandline -opc) + if [ (count $cmd) -gt 1 ] + if [ $argv[1] = $cmd[2] ] + return 0 end - return 1 + end + return 1 end -if command -s pyenv > /dev/null - complete -f -c pyenv -n '__fish_pyenv_needs_command' -a '(pyenv commands)' - for cmd in (pyenv commands) - complete -f -c pyenv -n "__fish_pyenv_using_command $cmd" -a "(pyenv completions $cmd)" - end +complete -f -c pyenv -n '__fish_pyenv_needs_command' -a '(pyenv commands)' +for cmd in (pyenv commands) + complete -f -c pyenv -n "__fish_pyenv_using_command $cmd" -a \ + "(pyenv completions (commandline -opc)[2..-1])" end diff --git a/config/fish/completions/pyenv.zsh b/config/fish/completions/pyenv.zsh new file mode 100644 index 0000000..08a4cee --- /dev/null +++ b/config/fish/completions/pyenv.zsh @@ -0,0 +1,18 @@ +if [[ ! -o interactive ]]; then + return +fi + +compctl -K _pyenv pyenv + +_pyenv() { + local words completions + read -cA words + + if [ "${#words}" -eq 2 ]; then + completions="$(pyenv commands)" + else + completions="$(pyenv completions ${words[2,-2]})" + fi + + reply=(${(ps:\n:)completions}) +} diff --git a/config/fish/conf.d/pyenv.fish b/config/fish/conf.d/pyenv.fish deleted file mode 100644 index 1e78700..0000000 --- a/config/fish/conf.d/pyenv.fish +++ /dev/null @@ -1,19 +0,0 @@ -if not command -s pyenv > /dev/null - echo "Install to use 'pyenv'." - exit 1 -end - -set -l pyenv_root "" - -if test -z "$PYENV_ROOT" - set pyenv_root ~/.pyenv - set -x PYENV_ROOT "$pyenv_root" -else - set pyenv_root "$PYENV_ROOT" -end - -if status --is-login - set -x PATH "$pyenv_root/shims" $PATH - set -x PYENV_SHELL fish -end -command mkdir -p "$pyenv_root/"{shims,versions} diff --git a/config/fish/fishfile b/config/fish/fishfile index d516033..d7d6908 100644 --- a/config/fish/fishfile +++ b/config/fish/fishfile @@ -3,5 +3,4 @@ jethrokuan/fzf simnalamburt/shellder fishgretel/fasd oh-my-fish/theme-bobthefish -pyenv -daenney/pyenv +yyuu/pyenv diff --git a/config/fish/functions/pyenv.fish b/config/fish/functions/pyenv.fish deleted file mode 100644 index 23b9cfd..0000000 --- a/config/fish/functions/pyenv.fish +++ /dev/null @@ -1,12 +0,0 @@ -function pyenv - set command $argv[1] - set -e argv[1] - - switch "$command" - case rehash shell - source (pyenv "sh-$command" $argv | psub) - - case \* - command pyenv "$command" $argv - end -end