Last active
August 30, 2023 02:01
-
-
Save eblocha/20dd80d911df7d9af64300160aabcb6b to your computer and use it in GitHub Desktop.
Custom fnm env
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if type fnm > /dev/null; then | |
export FNM_MULTISHELL_ROOT="/run/user/$UID/fnm_multishells" | |
export FNM_LOGLEVEL="info" | |
export FNM_VERSION_FILE_STRATEGY="local" | |
export FNM_MULTISHELL_PATH="$FNM_MULTISHELL_ROOT/$$" | |
export FNM_COREPACK_ENABLED="false" | |
export FNM_DIR="$HOME/.local/share/fnm" | |
export FNM_ARCH="x64" | |
export FNM_RESOLVE_ENGINES="false" | |
export FNM_NODE_DIST_MIRROR="https://nodejs.org/dist" | |
export PATH="$FNM_MULTISHELL_PATH/bin":$PATH | |
autoload -U add-zsh-hook | |
_fnm_on_exit () {{ | |
rm -f "$FNM_MULTISHELL_PATH" | |
}} | |
add-zsh-hook zshexit _fnm_on_exit && _fnm_on_exit | |
mkdir -p "$FNM_MULTISHELL_ROOT" | |
ln -s "$FNM_DIR/aliases/default" "$FNM_MULTISHELL_PATH" | |
rehash | |
_fnm_autoload_hook () {{ | |
if [[ -f .node-version || -f .nvmrc ]]; then | |
fnm use --silent-if-unchanged | |
fi | |
}} | |
add-zsh-hook chpwd _fnm_autoload_hook | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is my customized setup in .zshrc for fnm, which is a much faster alternative to nvm for managing multiple node installs.
Key changes to output from
fnm env
:ps -p <pid>
to detect dangling links.zshexit
hook to remove the symlink when the shell exits. Taken from the experimental branch in fnm here.--use-on-cd
option effect.I skip all of this if fnm is not installed.