fast-nvm: stop using locate and search recursively

This commit is contained in:
Guilherme Rugai Freire 2021-08-23 09:51:54 -03:00
parent 09a2f62c5d
commit 9014ff7043
No known key found for this signature in database
GPG Key ID: 0F9FE41723A8A297

View File

@ -1,5 +1,12 @@
locate_nvmrc() { list_nvmrc_recursive() {
locate -w .nvmrc | xargs -I'{}' realpath --relative-to=. '{}' | awk '/^(\.\.\/)*\.nvmrc$/ {print $0}' | sort | xargs -I'{}' realpath '{}' DIR="$(realpath "$1")"
/bin/ls "$DIR/.nvmrc" 2>/dev/null
PARENT_DIR="/$(realpath "$DIR/.." --relative-to=/)"
if [ "$DIR" != "/" ]; then list_nvmrc_recursive "$PARENT_DIR"; fi;
}
list_nvmrc() {
list_nvmrc_recursive . | sort
} }
export PATH="$HOME/.nvm/versions/node/$(/bin/cat $HOME/.nvm/alias/default)/bin:$PATH" export PATH="$HOME/.nvm/versions/node/$(/bin/cat $HOME/.nvm/alias/default)/bin:$PATH"
@ -7,10 +14,10 @@ nvm() {
. $HOME/.nvm/nvm.sh; nvm "$@" . $HOME/.nvm/nvm.sh; nvm "$@"
} }
DEFAULT=$(locate_nvmrc) DEFAULT=$(list_nvmrc)
cd() { cd() {
if builtin cd "$@" 2>/dev/null; then if builtin cd "$@" 2>/dev/null; then
FOUND="$(locate_nvmrc)" FOUND="$(list_nvmrc)"
if [ "$FOUND" != "" ] && [ "$DEFAULT" != "$FOUND" ]; then if [ "$FOUND" != "" ] && [ "$DEFAULT" != "$FOUND" ]; then
DEFAULT=$FOUND DEFAULT=$FOUND
nvm use nvm use