Skip to content

Commit

Permalink
Merge pull request jenv#5 from twlz0ne/add-fish-shell-support
Browse files Browse the repository at this point in the history
Add fish shell support
  • Loading branch information
doctorpangloss authored Jan 19, 2019
2 parents fb9315f + cdb62a8 commit df8f670
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 9 deletions.
22 changes: 22 additions & 0 deletions completions/jenv.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function __fish_jenv_needs_command
set cmd (commandline -opc)
if [ (count $cmd) -eq 1 -a $cmd[1] = 'jenv' ]
return 0
end
return 1
end

function __fish_jenv_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 jenv -n '__fish_jenv_needs_command' -a '(jenv commands)'
for cmd in (jenv commands)
complete -f -c jenv -n "__fish_jenv_using_command $cmd" -a "(jenv completions $cmd)"
end
57 changes: 48 additions & 9 deletions libexec/jenv-init
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ if [ -z "$print" ]; then
ksh )
profile='~/.profile'
;;
fish )
profile='~/.config/fish/config.fish'
;;
* )
profile='your profile'
;;
Expand All @@ -68,7 +71,14 @@ if [ -z "$print" ]; then
{ echo "# Load jenv automatically by adding"
echo "# the following to ${profile}:"
echo
echo 'eval "$(jenv init -)"'
case "$shell" in
fish )
echo 'status --is-interactive; and source (jenv init -|psub)'
;;
* )
echo 'eval "$(jenv init -)"'
;;
esac
echo
} >&2

Expand All @@ -77,28 +87,55 @@ fi

mkdir -p "${JENV_ROOT}/"{shims,plugins,versions}

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

case "$shell" in
fish )
echo "set -gx PATH '${JENV_ROOT}/shims' \$PATH"
echo "set -gx JENV_SHELL $shell"
echo "set -gx JENV_LOADED 1"
echo "set -e JAVA_HOME"
;;
bash | zsh )
echo "source \"$root/completions/jenv.${shell}\""
echo 'export PATH="'${JENV_ROOT}'/shims:${PATH}"'
echo "export JENV_SHELL=$shell"
echo "export JENV_LOADED=1"
echo "unset JAVA_HOME"
;;
esac

completion="${root}/completions/jenv.${shell}"
if [ -r "$completion" ]; then
echo "source '$completion'"
fi

if [ -z "$no_rehash" ]; then
echo 'jenv rehash 2>/dev/null'
fi

echo "export JENV_LOADED=1"
echo "unset JAVA_HOME"

for script in $(jenv-hooks init $shell); do
echo "source \"$script\""
done

commands=(`jenv-commands --sh`)
IFS="|"
cat <<EOS
case "$shell" in
fish )
IFS=" "
cat <<EOS
function jenv
set command \$argv[1]
set -e argv[1]
switch "\$command"
case ${commands[*]}
source (jenv "sh-\$command" \$argv|psub)
case '*'
command jenv "\$command" \$argv
end
end
EOS
;;
bash | zsh )
IFS="|"
cat <<EOS
jenv() {
typeset command
command="\$1"
Expand All @@ -114,3 +151,5 @@ jenv() {
esac
}
EOS
;;
esac

0 comments on commit df8f670

Please sign in to comment.