Skip to content

Commit

Permalink
feat: replace custom function to read .nvmrc with fnm --use-on-cd
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinocossar committed Feb 7, 2024
1 parent aaee068 commit d63fecb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 34 deletions.
33 changes: 0 additions & 33 deletions oh-my-custom-zsh.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -287,36 +287,3 @@ theme() {
fi
echo "Theme folder doesn't exist!"
}

# Auto read and apply .nvmrc with fnm
applynvmrc() {
if [ ! -f ".nvmrc" ]; then
return
fi

local node_version="$(node --version | grep -o '[^-]*$')"
local nvmrc_node_version="$(cat .nvmrc | tr -d " \t\n\r" )"

if [ ! -n $nvmrc_node_version ]; then
return
fi

case "$(tr -dc '.' <<<"$nvmrc_node_version" | awk '{ print length; }')" in
1)
if [ "$(echo $node_version | cut -d. -f1).$(echo $node_version | cut -d. -f2)" != $nvmrc_node_version ]; then
fnm use $nvmrc_node_version
fi
;;
2)
if [ $node_version != $nvmrc_node_version ]; then
fnm use $nvmrc_node_version
fi
;;
*)
if [ "$(echo $node_version | cut -d. -f1)" != $nvmrc_node_version ]; then
fnm use $nvmrc_node_version
fi
;;
esac
}
chpwd_functions=(${chpwd_functions[@]} "applynvmrc")
2 changes: 1 addition & 1 deletion zfiles/.zprofile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
eval "$(/opt/homebrew/bin/brew shellenv)"

# fnm
eval "$(fnm env)"
eval "$(fnm env --use-on-cd)"

# Golang
export GOPATH="$HOME/.go"
Expand Down

0 comments on commit d63fecb

Please sign in to comment.