diff --git a/completions/ndenv.fish b/completions/ndenv.fish new file mode 100644 index 0000000..24eb879 --- /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 (ndenv 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..499d755 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,10 +117,38 @@ if [ -z "$no_rehash" ]; then fi commands=(`ndenv-commands --sh`) +case "$shell" in +fish ) + cat </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