This commit is contained in:
Frank Qing
2025-06-06 14:31:52 +08:00
parent 6f34409205
commit f12bbb6ac1
3 changed files with 116 additions and 0 deletions

31
zshrc/fnm.zsh Normal file
View File

@@ -0,0 +1,31 @@
# fnm (Fast Node Manager) configuration
# https://github.com/Schniz/fnm
# Check if fnm is installed
if command -v fnm &> /dev/null; then
# Set fnm environment variables and enable auto-switching on directory change
eval "$(fnm env --use-on-cd --shell zsh)"
# Enable fnm completions for zsh
eval "$(fnm completions --shell zsh)"
# Optional: Auto-install Node.js version if .node-version exists but version not installed
# Uncomment the following lines to enable this feature:
# autoload -U add-zsh-hook
# _fnm_autoinstall() {
# if [[ -f .node-version || -f .nvmrc ]]; then
# local version
# if [[ -f .node-version ]]; then
# version="$(cat .node-version)"
# elif [[ -f .nvmrc ]]; then
# version="$(cat .nvmrc)"
# fi
# if ! fnm list | grep -q "$version"; then
# echo "Auto-installing Node.js $version..."
# fnm install "$version"
# fi
# fi
# }
# add-zsh-hook chpwd _fnm_autoinstall
# _fnm_autoinstall # Run on shell startup
fi