zsh: source fast-nvm script

this makes so if you cd into a directory with a .nvmrc, it will exec nvm
use
This commit is contained in:
Guilherme Rugai Freire 2021-08-20 17:14:13 -03:00
parent d60c4fe16b
commit a7eb216330
No known key found for this signature in database
GPG Key ID: 0F9FE41723A8A297
2 changed files with 28 additions and 4 deletions

27
.fast-nvm.sh Normal file
View File

@ -0,0 +1,27 @@
#!/bin/sh
locate_nvmrc() {
locate -w .nvmrc | xargs -I'{}' realpath --relative-to=. '{}' | awk '/^(\.\.\/)*\.nvmrc$/ {print $0}' | sort | xargs -I'{}' realpath '{}'
}
export PATH="$HOME/.nvm/versions/node/$(/bin/cat $HOME/.nvm/alias/default)/bin:$PATH"
nvm() {
. $HOME/.nvm/nvm.sh; nvm "$@"
}
DEFAULT=$(locate_nvmrc)
cd() {
if builtin cd "$@" 2>/dev/null; then
FOUND="$(locate_nvmrc)"
if [ "$DEFAULT" != "$FOUND" ]; then
DEFAULT=$FOUND
nvm use
fi
else
if test -f "$@"; then echo "cd: not a directory: $*"
elif test -d "$@"; then echo "cd: can not change to $*"
else echo "cd: no such file or directory: $*"
fi
return 1
fi
}

5
.zshrc
View File

@ -60,10 +60,7 @@ alias zathura="devour zathura"
alias ranger="source ranger"
# This loads nvm
export PATH="$HOME/.nvm/versions/node/$(/bin/cat $HOME/.nvm/alias/default)/bin:$PATH"
nvm() {
source $HOME/.nvm/nvm.sh; nvm "$@"
}
source $HOME/.fast-nvm.sh
# Check if is integrated terminal emulator
if [ -z "$INTEG_EMU" ]; then