mirror of
https://github.com/GRFreire/dotfiles.git
synced 2026-01-10 04:19:38 +00:00
fast-nvm: stop using locate and search recursively
This commit is contained in:
parent
09a2f62c5d
commit
9014ff7043
15
.fast-nvm.sh
15
.fast-nvm.sh
@ -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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user