Add proper pyenv support to fish

This commit is contained in:
Colin Powell
2018-12-07 13:40:10 -05:00
parent 574abe6975
commit ce96d464e3
6 changed files with 50 additions and 49 deletions

View File

@ -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

View File

@ -1,24 +1,23 @@
function __fish_pyenv_needs_command function __fish_pyenv_needs_command
set cmd (commandline -opc) set cmd (commandline -opc)
if test (count $cmd) -eq 1 -a "$cmd[1]" = "pyenv" if [ (count $cmd) -eq 1 -a $cmd[1] = 'pyenv' ]
return 0 return 0
end end
return 1 return 1
end end
function __fish_pyenv_using_command function __fish_pyenv_using_command
set cmd (commandline -opc) set cmd (commandline -opc)
if test (count $cmd) -gt 1 if [ (count $cmd) -gt 1 ]
if test "$argv[1]" = "$cmd[2]" if [ $argv[1] = $cmd[2] ]
return 0 return 0
end
end end
return 1 end
return 1
end end
if command -s pyenv > /dev/null complete -f -c pyenv -n '__fish_pyenv_needs_command' -a '(pyenv commands)'
complete -f -c pyenv -n '__fish_pyenv_needs_command' -a '(pyenv commands)' for cmd in (pyenv commands)
for cmd in (pyenv commands) complete -f -c pyenv -n "__fish_pyenv_using_command $cmd" -a \
complete -f -c pyenv -n "__fish_pyenv_using_command $cmd" -a "(pyenv completions $cmd)" "(pyenv completions (commandline -opc)[2..-1])"
end
end end

View File

@ -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})
}

View File

@ -1,19 +0,0 @@
if not command -s pyenv > /dev/null
echo "Install <github.com/yyuu/pyenv> 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}

View File

@ -3,5 +3,4 @@ jethrokuan/fzf
simnalamburt/shellder simnalamburt/shellder
fishgretel/fasd fishgretel/fasd
oh-my-fish/theme-bobthefish oh-my-fish/theme-bobthefish
pyenv yyuu/pyenv
daenney/pyenv

View File

@ -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