Browse Source

Merge pull request #5 from twlz0ne/add-fish-shell-support

Add fish shell support
pull/231/head
Benjamin Berman 7 years ago committed by GitHub
parent
commit
df8f6706c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      completions/jenv.fish
  2. 57
      libexec/jenv-init

22
completions/jenv.fish

@ -0,0 +1,22 @@ @@ -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
libexec/jenv-init

@ -60,6 +60,9 @@ if [ -z "$print" ]; then @@ -60,6 +60,9 @@ if [ -z "$print" ]; then
ksh )
profile='~/.profile'
;;
fish )
profile='~/.config/fish/config.fish'
;;
* )
profile='your profile'
;;
@ -68,7 +71,14 @@ if [ -z "$print" ]; then @@ -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
@ -77,28 +87,55 @@ fi @@ -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"
@ -114,3 +151,5 @@ jenv() { @@ -114,3 +151,5 @@ jenv() {
esac
}
EOS
;;
esac

Loading…
Cancel
Save