Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions completions/ndenv.fish
Original file line number Diff line number Diff line change
@@ -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
62 changes: 55 additions & 7 deletions libexec/ndenv-init
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ if [ -z "$print" ]; then
ksh )
profile='~/.profile'
;;
fish )
profile='~/.config/fish/config.fish'
;;
* )
profile='your profile'
;;
Expand All @@ -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

Expand All @@ -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
Expand All @@ -98,10 +117,38 @@ if [ -z "$no_rehash" ]; then
fi

commands=(`ndenv-commands --sh`)
case "$shell" in
fish )
cat <<EOS
function ndenv
set command \$argv[1]
set -e argv[1]
switch "\$command"
case ${commands[*]}
source (ndenv "sh-\$command" \$argv|psub)
case '*'
command ndenv "\$command" \$argv
end
end
EOS
;;
ksh )
cat <<EOS
function ndenv {
typeset command
EOS
;;
* )
cat <<EOS
ndenv() {
local command
EOS
;;
esac

if [ "$shell" != "fish" ]; then
IFS="|"
cat <<EOS
ndenv() {
typeset command
command="\$1"
if [ "\$#" -gt 0 ]; then
shift
Expand All @@ -115,3 +162,4 @@ ndenv() {
esac
}
EOS
fi
16 changes: 14 additions & 2 deletions libexec/ndenv-sh-rehash
Original file line number Diff line number Diff line change
Expand Up @@ -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