From 271c5fe4b4e036a1734d955bc9a3c90468da7f39 Mon Sep 17 00:00:00 2001 From: mtwtkman Date: Sat, 29 Nov 2014 11:08:17 +0900 Subject: [PATCH] add support for fish-shell --- completions/exenv.fish | 22 +++++++++++++++++++++ libexec/exenv-init | 43 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 completions/exenv.fish diff --git a/completions/exenv.fish b/completions/exenv.fish new file mode 100644 index 0000000..95fdce0 --- /dev/null +++ b/completions/exenv.fish @@ -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 diff --git a/libexec/exenv-init b/libexec/exenv-init index 046d1e6..e538978 100755 --- a/libexec/exenv-init +++ b/libexec/exenv-init @@ -17,7 +17,7 @@ do fi done -shell="$1" + if [ -z "$shell" ]; then shell="$(basename "$SHELL")" fi @@ -53,6 +53,9 @@ if [ -z "$print" ]; then ksh ) profile='~/.profile' ;; + fish ) + profile='~/.config/fish/config.fish' + ;; * ) profile='your profile' ;; @@ -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 @@ -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 @@ -83,6 +96,27 @@ if [ -z "$no_rehash" ]; then fi commands=(`exenv commands --sh`) +case "$shell" in +fish ) + cat <