From d16988316ec01ee35cd526a9b2a6f5b8c2fa3f39 Mon Sep 17 00:00:00 2001 From: Tomoyuki Hisasda Date: Tue, 25 Jul 2017 14:55:04 +0900 Subject: [PATCH 1/4] for fish --- completions/ndenv.fish | 22 ++++++++++++++++++++++ libexec/ndenv-init | 32 +++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 completions/ndenv.fish diff --git a/completions/ndenv.fish b/completions/ndenv.fish new file mode 100644 index 0000000..6e810de --- /dev/null +++ b/completions/ndenv.fish @@ -0,0 +1,22 @@ +function __fish_ndenv_needs_command + set cmd (commandline -opc) + if [ (count $cmd) -eq 1 -a $cmd[1] = 'ndenv' ] + return 0 + end + return 1 +end + +function __fish_ndenv_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 ndenv -n '__fish_ndenv_needs_command' -a '(ndenv commands)' +for cmd in (anyenv commands) + complete -f -c ndenv -n "__fish_ndenv_using_command $cmd" -a "(ndenv completions $cmd)" +end \ No newline at end of file diff --git a/libexec/ndenv-init b/libexec/ndenv-init index 3003370..efa01b7 100755 --- a/libexec/ndenv-init +++ b/libexec/ndenv-init @@ -66,6 +66,9 @@ if [ -z "$print" ]; then ksh ) profile='~/.profile' ;; + fish ) + profile='~/.config/fish/config.fish' + ;; * ) profile='your profile' ;; @@ -74,7 +77,14 @@ if [ -z "$print" ]; then { echo "# Load ndenv automatically by adding" echo "# the following to ${profile}:" echo - echo 'eval "$(ndenv init -)"' + case "$shell" in + fish ) + echo 'status --is-interactive; and source (ndenv init -|psub)' + ;; + * ) + echo 'eval "$(ndenv init -)"' + ;; + esac echo } >&2 @@ -83,12 +93,21 @@ fi mkdir -p "${NDENV_ROOT}/"{shims,versions} -if [[ ":${PATH}:" != *:"${NDENV_ROOT}/shims":* ]]; then - echo 'export PATH="'${NDENV_ROOT}'/shims:${PATH}"' -fi +case "$shell" in +fish ) + if [[ ":${PATH}:" != *:"${NDENV_ROOT}/shims":* ]]; then + echo 'set -gx PATH '${NDENV_ROOT}'/shims $PATH' + fi + ;; +* ) + if [[ ":${PATH}:" != *:"${NDENV_ROOT}/shims":* ]]; then + echo 'export PATH="'${NDENV_ROOT}'/shims:${PATH}"' + fi + ;; +esac case "$shell" in -bash | zsh ) +bash | zsh | fish ) echo "source \"$root/completions/ndenv.${shell}\"" ;; esac @@ -98,6 +117,8 @@ if [ -z "$no_rehash" ]; then fi commands=(`ndenv-commands --sh`) + +if [ "$shell" != "fish" ]; then IFS="|" cat < Date: Wed, 26 Jul 2017 11:57:03 +0900 Subject: [PATCH 2/4] fix --- completions/ndenv.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/ndenv.fish b/completions/ndenv.fish index 6e810de..24eb879 100644 --- a/completions/ndenv.fish +++ b/completions/ndenv.fish @@ -17,6 +17,6 @@ function __fish_ndenv_using_command end complete -f -c ndenv -n '__fish_ndenv_needs_command' -a '(ndenv commands)' -for cmd in (anyenv commands) +for cmd in (ndenv commands) complete -f -c ndenv -n "__fish_ndenv_using_command $cmd" -a "(ndenv completions $cmd)" end \ No newline at end of file From 09ce331fa8a333f03b462fed50483febc5113035 Mon Sep 17 00:00:00 2001 From: Tomoyuki Hisasda Date: Wed, 26 Jul 2017 12:36:08 +0900 Subject: [PATCH 3/4] fix --- libexec/ndenv-init | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/libexec/ndenv-init b/libexec/ndenv-init index efa01b7..499d755 100755 --- a/libexec/ndenv-init +++ b/libexec/ndenv-init @@ -117,12 +117,38 @@ if [ -z "$no_rehash" ]; then fi commands=(`ndenv-commands --sh`) +case "$shell" in +fish ) + cat < Date: Wed, 26 Jul 2017 13:50:32 +0900 Subject: [PATCH 4/4] fish is not suppot '||' so it was replaced by 'or' --- libexec/ndenv-sh-rehash | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libexec/ndenv-sh-rehash b/libexec/ndenv-sh-rehash index 78411f2..521b223 100755 --- a/libexec/ndenv-sh-rehash +++ b/libexec/ndenv-sh-rehash @@ -9,5 +9,17 @@ fi # When ndenv shell integration is enabled, delegate to ndenv-rehash, # then tell the shell to empty its command lookup cache. -ndenv-rehash -echo "hash -r 2>/dev/null || true" +shell="$1" +if [ -z "$shell" ]; then + shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)" + shell="${shell##-}" + shell="${shell%% *}" + shell="${shell:-$SHELL}" + shell="${shell##*/}" +fi + +if [ "$shell" == "fish" ]; then + echo "hash -r 2>/dev/null or true" +else + echo "hash -r 2>/dev/null || true" +fi \ No newline at end of file