Update
This commit is contained in:
85
install_fnm.sh
Executable file
85
install_fnm.sh
Executable file
@@ -0,0 +1,85 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Save the original working directory
|
||||||
|
ORIGINAL_DIR="$(pwd)"
|
||||||
|
|
||||||
|
# Function to detect the operating system
|
||||||
|
detect_os() {
|
||||||
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
echo "macos"
|
||||||
|
elif [[ -f /etc/os-release ]]; then
|
||||||
|
. /etc/os-release
|
||||||
|
echo "$ID"
|
||||||
|
else
|
||||||
|
echo "unknown"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install fnm (Fast Node Manager) if it is not already installed
|
||||||
|
if command -v fnm &> /dev/null; then
|
||||||
|
echo -e "fnm is already installed\n"
|
||||||
|
fnm --version
|
||||||
|
else
|
||||||
|
echo -e "Installing fnm (Fast Node Manager)\n"
|
||||||
|
|
||||||
|
os=$(detect_os)
|
||||||
|
|
||||||
|
case $os in
|
||||||
|
macos)
|
||||||
|
# Try homebrew first on macOS
|
||||||
|
if command -v brew &> /dev/null; then
|
||||||
|
echo "Installing fnm via Homebrew..."
|
||||||
|
brew install fnm
|
||||||
|
else
|
||||||
|
echo "Installing fnm via official installer..."
|
||||||
|
curl -fsSL https://fnm.vercel.app/install | bash
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
ubuntu|debian)
|
||||||
|
# Use the official installer for Linux
|
||||||
|
echo "Installing fnm via official installer..."
|
||||||
|
curl -fsSL https://fnm.vercel.app/install | bash
|
||||||
|
;;
|
||||||
|
fedora|centos|rhel)
|
||||||
|
# Use the official installer for RHEL-based distros
|
||||||
|
echo "Installing fnm via official installer..."
|
||||||
|
curl -fsSL https://fnm.vercel.app/install | bash
|
||||||
|
;;
|
||||||
|
arch|manjaro)
|
||||||
|
# Use the official installer for Arch-based distros
|
||||||
|
echo "Installing fnm via official installer..."
|
||||||
|
curl -fsSL https://fnm.vercel.app/install | bash
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Using official installer for unknown OS..."
|
||||||
|
curl -fsSL https://fnm.vercel.app/install | bash
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Load fnm for the remainder of this script
|
||||||
|
export PATH="$HOME/.local/share/fnm:$PATH"
|
||||||
|
eval "$(fnm env --use-on-cd)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# OPTIONAL: Install the latest LTS version of Node.js
|
||||||
|
# Uncomment the following lines if you would like to automatically install it
|
||||||
|
# echo "Installing latest LTS Node.js version..."
|
||||||
|
# fnm install --lts
|
||||||
|
# fnm use lts-latest
|
||||||
|
# fnm default lts-latest
|
||||||
|
|
||||||
|
# Apply the fnm zsh configuration patch (downloads zshrc/fnm.zsh to ~/.config/zshrc/fnm.zsh)
|
||||||
|
curl -s https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s fnm
|
||||||
|
|
||||||
|
echo -e "\nfnm installation completed!"
|
||||||
|
echo -e "To start using fnm, restart your terminal or run: source ~/.zshrc"
|
||||||
|
echo -e "\nUseful fnm commands:"
|
||||||
|
echo -e " fnm install --lts # Install latest LTS Node.js"
|
||||||
|
echo -e " fnm install 18 # Install Node.js v18"
|
||||||
|
echo -e " fnm use 18 # Use Node.js v18"
|
||||||
|
echo -e " fnm default 18 # Set Node.js v18 as default"
|
||||||
|
echo -e " fnm list # List installed versions"
|
||||||
|
echo -e " fnm list-remote # List available versions"
|
||||||
|
|
||||||
|
# Restore original working directory
|
||||||
|
cd "$ORIGINAL_DIR"
|
||||||
0
install_merlin_worker.sh
Normal file → Executable file
0
install_merlin_worker.sh
Normal file → Executable file
31
zshrc/fnm.zsh
Normal file
31
zshrc/fnm.zsh
Normal 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
|
||||||
Reference in New Issue
Block a user