From f12bbb6ac1b06a9ea5c9e2cb575e84421b7479a1 Mon Sep 17 00:00:00 2001 From: Frank Qing Date: Fri, 6 Jun 2025 14:31:52 +0800 Subject: [PATCH] Update --- install_fnm.sh | 85 ++++++++++++++++++++++++++++++++++++++++ install_merlin_worker.sh | 0 zshrc/fnm.zsh | 31 +++++++++++++++ 3 files changed, 116 insertions(+) create mode 100755 install_fnm.sh mode change 100644 => 100755 install_merlin_worker.sh create mode 100644 zshrc/fnm.zsh diff --git a/install_fnm.sh b/install_fnm.sh new file mode 100755 index 0000000..fcad378 --- /dev/null +++ b/install_fnm.sh @@ -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" \ No newline at end of file diff --git a/install_merlin_worker.sh b/install_merlin_worker.sh old mode 100644 new mode 100755 diff --git a/zshrc/fnm.zsh b/zshrc/fnm.zsh new file mode 100644 index 0000000..59c7dd2 --- /dev/null +++ b/zshrc/fnm.zsh @@ -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 \ No newline at end of file