Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

add support for fish-shell #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions completions/exenv.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function __fish_exenv_needs_command
set cmd (commandline -opc)
if [ (count $cmd) -eq 1 -a $cmd[1] = 'exenv' ]
return 0
end
return 1
end

function __fish_exenv_using_command
set cmd (commandline -opc)
if [ (count $cmd) -gt 1 ]
if [ $argv[1] = $cmd[2] ]
return 0
end
end
return 1
end

complete -f -c exenv -n '__fish_exenv_needs_command' -a '(exenv commands)'
for cmd in (exenv commands)
complete -f -c exenv -n "__fish_exenv_using_command $cmd" -a "(exenv completions $cmd)"
end
43 changes: 39 additions & 4 deletions libexec/exenv-init
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ do
fi
done

shell="$1"

if [ -z "$shell" ]; then
shell="$(basename "$SHELL")"
fi
Expand Down Expand Up @@ -53,6 +53,9 @@ if [ -z "$print" ]; then
ksh )
profile='~/.profile'
;;
fish )
profile='~/.config/fish/config.fish'
;;
* )
profile='your profile'
;;
Expand All @@ -61,7 +64,14 @@ if [ -z "$print" ]; then
{ echo "# Load exenv automatically by adding"
echo "# the following to ${profile}:"
echo
echo 'eval "$(exenv init -)"'
case "$shell" in
fish )
echo 'status --is-interactive; and . (exenv init -|psub)'
;;
* )
echo 'eval "$(exenv init -)"'
;;
esac
echo
} >&2

Expand All @@ -70,10 +80,13 @@ fi

mkdir -p "${EXENV_ROOT}/"{shims,versions}

echo 'export PATH="'${EXENV_ROOT}'/shims:${PATH}"'

case "$shell" in
fish )
echo "setenv PATH '${EXENV_ROOT}/shims' \$PATH"
echo ". \"$root/completions/exenv.${shell}\""
;;
bash | zsh )
echo 'export PATH="'${EXENV_ROOT}'/shims:${PATH}"'
echo "source \"$root/completions/exenv.${shell}\""
;;
esac
Expand All @@ -83,6 +96,27 @@ if [ -z "$no_rehash" ]; then
fi

commands=(`exenv commands --sh`)
case "$shell" in
fish )
cat <<EOS
function exenv
set command \$argv[1]
set -e argv[1]

switch "\$command"
case ${commands[*]}
eval (exenv "sh-\$command" \$argv)
case '*'
command exenv "\$command" \$argv
end
end
EOS
;;
* )
;;
esac

if [ "$shell" != "fish" ]; then
IFS="|"
cat <<EOS
exenv() {
Expand All @@ -99,3 +133,4 @@ exenv() {
esac
}
EOS
fi