Compare commits

..

27 Commits

Author SHA1 Message Date
Yuhao Qing
9641876d43 Add a new option 2025-12-18 18:10:03 +08:00
Yuhao Qing
d8238c545a fix 2025-12-18 18:07:17 +08:00
Yuhao Qing
76549f5438 merlin zsh compatible 2025-12-18 17:42:46 +08:00
Yuhao Qing
a7dcd7c271 Stage prep_env.sh 2025-12-18 17:42:20 +08:00
Frank Qing
8c84b3dbf6 Enhance installation script by adding autoconf to the list of required packages and updating installation checks accordingly. 2025-10-24 17:43:55 +08:00
Frank Qing
a8ed0f080a Update fnm installation 2025-06-13 14:07:38 +08:00
Frank Qing
b017fb1592 Fix: add missing newline at end of file in nvm.zsh and pyenv.zsh for consistency 2025-06-07 19:22:56 +08:00
Frank Qing
d1537fa0a3 (fnm.zsh): update FNM_PATH to use HOME variable and enhance fnm environment initialization for zsh 2025-06-06 23:12:59 +08:00
Frank Qing
847ec3b650 Update 2025-06-06 14:46:18 +08:00
Frank Qing
f12bbb6ac1 Update 2025-06-06 14:31:52 +08:00
Frank Qing
6f34409205 (merlin_devbox.zsh): remove hardcoded HF_ENDPOINT variable to streamline proxy configuration and enhance flexibility in environment settings 2025-06-06 14:23:51 +08:00
Frank Qing
3d5cf87929 (.zshrc, nvm.zsh): comment out unused plugins in .zshrc and refactor nvm initialization to improve function handling for nvm, node, and npm commands 2025-06-06 00:15:07 +08:00
Frank Qing
3b820fce60 (merlin_devbox.zsh, merlin_worker.zsh): consolidate proxy configurations and aliases for Hugging Face and HTTP proxies, enhancing endpoint management and consistency across environments 2025-06-05 23:37:32 +08:00
Frank Qing
ad6d3fe8fc Update 2025-06-05 23:22:57 +08:00
Frank Qing
1043318893 Update 2025-06-05 23:19:27 +08:00
Frank Qing
5a66025db5 Update 2025-05-29 17:27:23 +08:00
Frank Qing
5e94ac33a6 (merlin_devbox.zsh, merlin_worker.zsh): update proxy configuration to include additional domains for no_proxy and enhance proxy_on alias for improved endpoint management 2025-05-28 17:35:21 +08:00
Frank Qing
5088da8a75 (install.sh, install_nvm.sh): refactor font installation logic to check for existing fonts before downloading, and remove redundant echo statement in install_nvm.sh 2025-05-28 15:11:24 +08:00
Frank Qing
18a56766c6 (merlin_worker.zsh): update proxy configuration to include new internal and external mirrors, and add aliases for easier endpoint management 2025-05-28 14:37:27 +08:00
Frank Qing
bff631f971 (merlin_devbox.zsh): remove custom configurations for user-specific script sourcing 2025-05-28 04:46:05 +08:00
Frank Qing
4eb890e26a (merlin_worker.zsh): add proxy configuration and aliases for enabling/disabling proxy settings in zsh environment 2025-05-28 04:29:46 +08:00
Frank Qing
e3e219e55b (install.sh): refactor eza installation logic to streamline package manager checks and enhance fallback methods for various operating systems 2025-05-28 04:24:44 +08:00
Frank Qing
1bd3a2dcb8 (install.sh): update eza installation logic to install via cargo if Rust is not present, removing previous GPG and repository setup steps 2025-05-28 04:07:10 +08:00
Frank Qing
e515a8b4bc (install_nvm.sh): update zsh configuration patch to apply nvm setup instead of basic configuration 2025-05-28 03:44:57 +08:00
Frank Qing
158a1388bc (install_merlin_worker.sh): enhance installation script with error handling, cross-platform compatibility for sed, and improved directory management for merlin_worker.zsh 2025-05-28 03:40:25 +08:00
Frank Qing
68625d2e21 (install.sh, merlin_worker.zsh): enhance installation script with fallback methods for eza and zoxide, and add proxy configuration to zsh environment 2025-05-28 03:28:01 +08:00
Frank Qing
0492b6a053 (.zshrc, install.sh): enhance zsh configuration with additional plugin support and improve installation logic for better cross-OS compatibility 2025-05-28 03:03:57 +08:00
14 changed files with 944 additions and 108 deletions

16
.zshrc
View File

@@ -6,9 +6,9 @@ fi
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
# source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
# fi
export TERM="xterm-256color"
# If you come from bash you might have to change your $PATH.
@@ -69,11 +69,11 @@ plugins=(
# zsh-completions INSTALL METHOD CHANGED https://github.com/zsh-users/zsh-completions/issues/603
zsh-autosuggestions
zsh-syntax-highlighting
history-substring-search
systemd
k
extract
sudo
# history-substring-search
# systemd
# k
# extract
# sudo
fzf-tab
# web-search
# httpie

View File

@@ -42,132 +42,133 @@ detect_os() {
fi
}
# Function to install packages
install_packages() {
# Install eza using package manager or fallback methods
install_eza() {
local os=$(detect_os)
echo "Installing eza..."
case $os in
macos)
if ! command -v brew &> /dev/null; then
echo "Homebrew is not installed. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew install zsh git wget fontconfig eza zoxide
brew install eza
;;
ubuntu|debian)
sudo apt-get update
sudo apt-get install -y zsh git wget fontconfig
# Install eza if not already installed
if ! command -v eza &> /dev/null; then
echo "Installing eza..."
# Install GPG if not present
if ! command -v gpg &> /dev/null; then
sudo apt install -y gpg
if ! sudo apt-get install -y eza; then
echo "Package manager installation failed, attempting fallback..."
# Install cargo if it doesn't exist
if ! command -v cargo &> /dev/null; then
echo "Installing Rust and cargo..."
sudo apt-get update
sudo apt-get install -y curl build-essential
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source ~/.cargo/env
fi
# Add eza repository and install
sudo mkdir -p /etc/apt/keyrings
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | sudo gpg --dearmor -o /etc/apt/keyrings/gierens.gpg
echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" | sudo tee /etc/apt/sources.list.d/gierens.list
sudo chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list
sudo apt update
sudo apt install -y eza
fi
# Install zoxide if not already installed
if ! command -v zoxide &> /dev/null; then
echo "Installing zoxide..."
curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
cargo install eza
fi
;;
fedora)
sudo dnf install -y zsh git wget fontconfig
# Install eza if not already installed
if ! command -v eza &> /dev/null; then
echo "Installing eza..."
# For Fedora versions prior to 42
if ! sudo dnf install -y eza; then
echo "eza not available in official repository, installing from cargo..."
echo "Package manager installation failed, attempting fallback..."
if command -v cargo &> /dev/null; then
cargo install eza
else
echo "cargo not found. Please install Rust/cargo first or install eza manually."
fi
fi
fi
# Install zoxide if not already installed
if ! command -v zoxide &> /dev/null; then
echo "Installing zoxide..."
# zoxide is available in Fedora 32+
if ! sudo dnf install -y zoxide; then
echo "zoxide not available in official repository, installing from install script..."
curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
wget -qO- https://github.com/eza-community/eza/releases/latest/download/eza_x86_64-unknown-linux-gnu.tar.gz | tar xz
sudo install -m 755 eza /usr/local/bin/eza
fi
fi
;;
centos|rhel)
sudo yum install -y zsh git wget fontconfig
# Install eza if not already installed
if ! command -v eza &> /dev/null; then
echo "Installing eza..."
# Install from cargo as primary method
if ! sudo yum install -y eza; then
echo "Package manager installation failed, attempting fallback..."
if command -v cargo &> /dev/null; then
cargo install eza
else
echo "cargo not found. Installing from binary..."
wget -c https://github.com/eza-community/eza/releases/latest/download/eza_x86_64-unknown-linux-gnu.tar.gz -O - | tar xz
sudo chmod +x eza
sudo chown root:root eza
sudo mv eza /usr/local/bin/eza
fi
fi
# Install zoxide if not already installed
if ! command -v zoxide &> /dev/null; then
echo "Installing zoxide..."
# Try dnf first (RHEL 8+ and CentOS Stream have zoxide in EPEL), fallback to install script
if ! (command -v dnf &> /dev/null && sudo dnf install -y zoxide); then
echo "Installing zoxide from install script..."
curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
wget -qO- https://github.com/eza-community/eza/releases/latest/download/eza_x86_64-unknown-linux-gnu.tar.gz | tar xz
sudo install -m 755 eza /usr/local/bin/eza
fi
fi
;;
arch|manjaro)
sudo pacman -Syu --noconfirm zsh git wget fontconfig eza zoxide
if ! sudo pacman -Syu --noconfirm eza; then
echo "Package manager installation failed, attempting fallback..."
wget -qO- https://github.com/eza-community/eza/releases/latest/download/eza_x86_64-unknown-linux-gnu.tar.gz | tar xz
sudo install -m 755 eza /usr/local/bin/eza
fi
;;
*)
echo "Unsupported operating system. Please install zsh, git, wget, and fontconfig manually."
# Try to install eza from binary for unsupported systems
if ! command -v eza &> /dev/null; then
echo "Installing eza from binary..."
wget -c https://github.com/eza-community/eza/releases/latest/download/eza_x86_64-unknown-linux-gnu.tar.gz -O - | tar xz
sudo chmod +x eza
sudo chown root:root eza
sudo mv eza /usr/local/bin/eza
fi
# Try to install zoxide for unsupported systems
if ! command -v zoxide &> /dev/null; then
echo "Installing zoxide from install script..."
curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
fi
exit 1
echo "Unsupported operating system for package manager installation, using fallback..."
wget -qO- https://github.com/eza-community/eza/releases/latest/download/eza_x86_64-unknown-linux-gnu.tar.gz | tar xz
sudo install -m 755 eza /usr/local/bin/eza
;;
esac
}
# Helper: install zoxide if the package manager couldn't provide it
install_zoxide_fallback() {
local os=$(detect_os)
echo "Attempting fallback installation of zoxide..."
case $os in
fedora)
sudo dnf install -y zoxide || curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
;;
centos|rhel)
if command -v dnf &> /dev/null && sudo dnf install -y zoxide; then :; else
curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
fi
;;
*)
curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
;;
esac
}
# Core: install required packages via the preferred package manager, then fall back where needed
install_packages() {
local os=$(detect_os)
local base_packages="zsh git wget fontconfig zoxide autoconf"
case $os in
macos)
if ! command -v brew &> /dev/null; then
echo "Homebrew is not installed. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew install ${base_packages}
;;
ubuntu|debian)
sudo apt-get update
sudo apt-get install -y ${base_packages}
;;
fedora)
sudo dnf install -y ${base_packages}
;;
centos|rhel)
sudo yum install -y ${base_packages}
;;
arch|manjaro)
sudo pacman -Syu --noconfirm ${base_packages}
;;
*)
echo "Unsupported operating system. Please install ${base_packages} manually."
;;
esac
# Fallbacks for any tools that are still missing after the package-manager step
command -v eza &> /dev/null || install_eza
command -v zoxide &> /dev/null || install_zoxide_fallback
}
# Check if required packages are installed, if not, install them
if command -v zsh &> /dev/null && command -v git &> /dev/null && command -v wget &> /dev/null && command -v fc-cache &> /dev/null && command -v eza &> /dev/null && command -v zoxide &> /dev/null; then
echo -e "ZSH, Git, wget, fontconfig, eza, and zoxide are already installed\n"
if command -v zsh &> /dev/null && command -v git &> /dev/null && command -v wget &> /dev/null && command -v fc-cache &> /dev/null && command -v eza &> /dev/null && command -v zoxide &> /dev/null && command -v autoconf &> /dev/null; then
echo -e "ZSH, Git, wget, fontconfig, eza, zoxide, and autoconf are already installed\n"
else
echo "Installing required packages..."
install_packages
echo -e "zsh, wget, git, fontconfig, eza, and zoxide Installed\n"
echo -e "zsh, wget, git, fontconfig, eza, zoxide, and autoconf Installed\n"
fi
if [ -f ~/.gitconfig.backup ]; then
@@ -247,9 +248,29 @@ fi
echo -e "Installing Nerd Fonts version of Hack, Roboto Mono, DejaVu Sans Mono\n"
# Check and download Hack font if it doesn't exist
if [ ! -f ~/.fonts/HackNerdFont-Regular.ttf ]; then
echo "Downloading Hack Nerd Font..."
wget -q --show-progress -N https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/Hack/Regular/HackNerdFont-Regular.ttf -P ~/.fonts/
else
echo "Hack Nerd Font already exists, skipping download."
fi
# Check and download Roboto Mono font if it doesn't exist
if [ ! -f ~/.fonts/RobotoMonoNerdFont-Regular.ttf ]; then
echo "Downloading Roboto Mono Nerd Font..."
wget -q --show-progress -N https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/RobotoMono/Regular/RobotoMonoNerdFont-Regular.ttf -P ~/.fonts/
else
echo "Roboto Mono Nerd Font already exists, skipping download."
fi
# Check and download DejaVu Sans Mono font if it doesn't exist
if [ ! -f ~/.fonts/DejaVuSansMNerdFont-Regular.ttf ]; then
echo "Downloading DejaVu Sans Mono Nerd Font..."
wget -q --show-progress -N https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DejaVuSansMono/Regular/DejaVuSansMNerdFont-Regular.ttf -P ~/.fonts/
else
echo "DejaVu Sans Mono Nerd Font already exists, skipping download."
fi
fc-cache -fv ~/.fonts

230
install/fnm.sh Normal file
View File

@@ -0,0 +1,230 @@
#!/bin/bash
set -e
RELEASE="latest"
OS="$(uname -s)"
case "${OS}" in
MINGW* | Win*) OS="Windows" ;;
esac
if [ -d "$HOME/.fnm" ]; then
INSTALL_DIR="$HOME/.fnm"
elif [ -n "$XDG_DATA_HOME" ]; then
INSTALL_DIR="$XDG_DATA_HOME/fnm"
elif [ "$OS" = "Darwin" ]; then
INSTALL_DIR="$HOME/Library/Application Support/fnm"
else
INSTALL_DIR="$HOME/.local/share/fnm"
fi
# Parse Flags
parse_args() {
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-d | --install-dir)
INSTALL_DIR="$2"
shift # past argument
shift # past value
;;
-s | --skip-shell)
SKIP_SHELL="true"
shift # past argument
;;
--force-install | --force-no-brew)
echo "\`--force-install\`: I hope you know what you're doing." >&2
FORCE_INSTALL="true"
shift
;;
-r | --release)
RELEASE="$2"
shift # past release argument
shift # past release value
;;
*)
echo "Unrecognized argument $key"
exit 1
;;
esac
done
}
set_filename() {
if [ "$OS" = "Linux" ]; then
# Based on https://stackoverflow.com/a/45125525
case "$(uname -m)" in
arm | armv7*)
FILENAME="fnm-arm32"
;;
aarch* | armv8*)
FILENAME="fnm-arm64"
;;
*)
FILENAME="fnm-linux"
esac
elif [ "$OS" = "Darwin" ] && [ "$FORCE_INSTALL" = "true" ]; then
FILENAME="fnm-macos"
USE_HOMEBREW="false"
echo "Downloading the latest fnm binary from GitHub..."
echo " Pro tip: it's easier to use Homebrew for managing fnm in macOS."
echo " Remove the \`--force-no-brew\` so it will be easy to upgrade."
elif [ "$OS" = "Darwin" ]; then
USE_HOMEBREW="true"
echo "Downloading fnm using Homebrew..."
elif [ "$OS" = "Windows" ] ; then
FILENAME="fnm-windows"
echo "Downloading the latest fnm binary from GitHub..."
else
echo "OS $OS is not supported."
echo "If you think that's a bug - please file an issue to https://github.com/Schniz/fnm/issues"
exit 1
fi
}
download_fnm() {
if [ "$USE_HOMEBREW" = "true" ]; then
brew install fnm
else
if [ "$RELEASE" = "latest" ]; then
URL="https://github.com/Schniz/fnm/releases/latest/download/$FILENAME.zip"
else
URL="https://github.com/Schniz/fnm/releases/download/$RELEASE/$FILENAME.zip"
fi
DOWNLOAD_DIR=$(mktemp -d)
echo "Downloading $URL..."
mkdir -p "$INSTALL_DIR" &>/dev/null
if ! curl --progress-bar --fail -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME.zip"; then
echo "Download failed. Check that the release/filename are correct."
exit 1
fi
unzip -q "$DOWNLOAD_DIR/$FILENAME.zip" -d "$DOWNLOAD_DIR"
if [ -f "$DOWNLOAD_DIR/fnm" ]; then
mv "$DOWNLOAD_DIR/fnm" "$INSTALL_DIR/fnm"
else
mv "$DOWNLOAD_DIR/$FILENAME/fnm" "$INSTALL_DIR/fnm"
fi
chmod u+x "$INSTALL_DIR/fnm"
fi
}
check_dependencies() {
echo "Checking dependencies for the installation script..."
echo -n "Checking availability of curl... "
if hash curl 2>/dev/null; then
echo "OK!"
else
echo "Missing!"
SHOULD_EXIT="true"
fi
echo -n "Checking availability of unzip... "
if hash unzip 2>/dev/null; then
echo "OK!"
else
echo "Missing!"
SHOULD_EXIT="true"
fi
if [ "$USE_HOMEBREW" = "true" ]; then
echo -n "Checking availability of Homebrew (brew)... "
if hash brew 2>/dev/null; then
echo "OK!"
else
echo "Missing!"
SHOULD_EXIT="true"
fi
fi
if [ "$SHOULD_EXIT" = "true" ]; then
echo "Not installing fnm due to missing dependencies."
exit 1
fi
}
ensure_containing_dir_exists() {
local CONTAINING_DIR
CONTAINING_DIR="$(dirname "$1")"
if [ ! -d "$CONTAINING_DIR" ]; then
echo " >> Creating directory $CONTAINING_DIR"
mkdir -p "$CONTAINING_DIR"
fi
}
setup_shell() {
CURRENT_SHELL="$(basename "$SHELL")"
if [ "$CURRENT_SHELL" = "zsh" ]; then
CONF_FILE=${ZDOTDIR:-$HOME}/.zshrc
ensure_containing_dir_exists "$CONF_FILE"
echo "Installing for Zsh. Appending the following to $CONF_FILE:"
{
echo ''
echo '# fnm'
echo 'FNM_PATH="'"$INSTALL_DIR"'"'
echo 'if [ -d "$FNM_PATH" ]; then'
echo ' export PATH="'$INSTALL_DIR':$PATH"'
echo ' eval "`fnm env`"'
echo 'fi'
} | tee -a "$CONF_FILE"
elif [ "$CURRENT_SHELL" = "fish" ]; then
CONF_FILE=$HOME/.config/fish/conf.d/fnm.fish
ensure_containing_dir_exists "$CONF_FILE"
echo "Installing for Fish. Appending the following to $CONF_FILE:"
{
echo ''
echo '# fnm'
echo 'set FNM_PATH "'"$INSTALL_DIR"'"'
echo 'if [ -d "$FNM_PATH" ]'
echo ' set PATH "$FNM_PATH" $PATH'
echo ' fnm env | source'
echo 'end'
} | tee -a "$CONF_FILE"
elif [ "$CURRENT_SHELL" = "bash" ]; then
if [ "$OS" = "Darwin" ]; then
CONF_FILE=$HOME/.profile
else
CONF_FILE=$HOME/.bashrc
fi
ensure_containing_dir_exists "$CONF_FILE"
echo "Installing for Bash. Appending the following to $CONF_FILE:"
{
echo ''
echo '# fnm'
echo 'FNM_PATH="'"$INSTALL_DIR"'"'
echo 'if [ -d "$FNM_PATH" ]; then'
echo ' export PATH="$FNM_PATH:$PATH"'
echo ' eval "`fnm env`"'
echo 'fi'
} | tee -a "$CONF_FILE"
else
echo "Could not infer shell type. Please set up manually."
exit 1
fi
echo ""
echo "In order to apply the changes, open a new terminal or run the following command:"
echo ""
echo " source $CONF_FILE"
}
parse_args "$@"
set_filename
check_dependencies
download_fnm
if [ "$SKIP_SHELL" != "true" ]; then
setup_shell
fi

85
install_fnm.sh Executable file
View 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://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash
fi
;;
ubuntu|debian)
# Use the official installer for Linux
echo "Installing fnm via official installer..."
curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash
;;
fedora|centos|rhel)
# Use the official installer for RHEL-based distros
echo "Installing fnm via official installer..."
curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash
;;
arch|manjaro)
# Use the official installer for Arch-based distros
echo "Installing fnm via official installer..."
curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash
;;
*)
echo "Using official installer for unknown OS..."
curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | 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 -fsSL 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"

50
install_merlin_worker.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/bash
# Exit on any error
set -e
# Download and execute the patch script
if ! curl -s https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s merlin_worker; then
echo "Error: Failed to download or execute patch script"
exit 1
fi
# Check if ~/.bashrc exists and contains PYTHONPATH export
if [ -f "$HOME/.bashrc" ]; then
# Extract PYTHONPATH from ~/.bashrc (look for export PYTHONPATH=...)
BASHRC_PYTHONPATH=$(grep -E "^export PYTHONPATH=" "$HOME/.bashrc" | tail -1)
if [ -n "$BASHRC_PYTHONPATH" ]; then
echo "Found PYTHONPATH in ~/.bashrc: $BASHRC_PYTHONPATH"
# Path to the merlin_worker.zsh file
MERLIN_CONFIG="$HOME/.config/zshrc/merlin_worker.zsh"
# Create directory if it doesn't exist
mkdir -p "$(dirname "$MERLIN_CONFIG")"
if [ -f "$MERLIN_CONFIG" ]; then
# Cross-platform sed: remove existing PYTHONPATH lines
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' '/^export PYTHONPATH=/d' "$MERLIN_CONFIG"
else
# Linux/Ubuntu and others
sed -i '/^export PYTHONPATH=/d' "$MERLIN_CONFIG"
fi
# Then append the PYTHONPATH from ~/.bashrc
echo "$BASHRC_PYTHONPATH" >> "$MERLIN_CONFIG"
echo "Updated PYTHONPATH in $MERLIN_CONFIG with value from ~/.bashrc"
else
# Create the file with just the PYTHONPATH
echo "$BASHRC_PYTHONPATH" > "$MERLIN_CONFIG"
echo "Created $MERLIN_CONFIG with PYTHONPATH from ~/.bashrc"
fi
else
echo "No PYTHONPATH export found in ~/.bashrc"
fi
else
echo "~/.bashrc not found"
fi

View File

@@ -21,9 +21,7 @@ fi
nvm install --lts
# Apply the "basic" zsh configuration patch (downloads zshrc/basic.zsh to ~/.config/zshrc/basic.zsh)
curl -s https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s basic
curl -s https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s nvm
# Restore original working directory
cd "$ORIGINAL_DIR"
echo -e "\nAll basic packages have been installed. Restart your terminal or run 'source ~/.zshrc' to start using them.\n"

28
install_pyenv.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
# Save the original working directory
ORIGINAL_DIR="$(pwd)"
# Install pyenv (Python Version Manager) if it is not already installed
if command -v pyenv &> /dev/null; then
echo -e "pyenv is already installed\n"
else
echo -e "Installing pyenv (Python Version Manager)\n"
# Using the official pyenv installer (https://github.com/pyenv/pyenv-installer)
curl -fsSL https://pyenv.run | bash
# Load pyenv for the remainder of this script
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init - bash)"
fi
# OPTIONAL: Install the latest stable version of Python
# Uncomment the following line if you would like to automatically install it
# pyenv install 3.12.0 && pyenv global 3.12.0
# Apply the pyenv zsh configuration patch (downloads zshrc/pyenv.zsh to ~/.config/zshrc/pyenv.zsh)
curl -s https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s pyenv
# Restore original working directory
cd "$ORIGINAL_DIR"

8
zshrc/fnm.zsh Normal file
View File

@@ -0,0 +1,8 @@
# fnm (Fast Node Manager) configuration
# https://github.com/Schniz/fnm
FNM_PATH="$HOME/.local/share/fnm"
if [ -d "$FNM_PATH" ]; then
export PATH="$HOME/.local/share/fnm:$PATH"
eval "$(fnm env --use-on-cd --shell zsh)"
fi

56
zshrc/merlin_devbox.zsh Normal file
View File

@@ -0,0 +1,56 @@
# # Patch prep_env.sh for zsh compatibility (only if not already patched)
# _prep_env="/workspace/vscode/prep_env.sh"
# if [[ -f "$_prep_env" ]] && ! grep -q '# PATCHED_FOR_ZSH' "$_prep_env" 2>/dev/null; then
# sed -i \
# -e '1a# PATCHED_FOR_ZSH' \
# -e 's/^shopt -s histappend$/[[ -n "${BASH_VERSION}" ]] \&\& shopt -s histappend/' \
# -e 's/\${!\([^}]*\)}/\$( [[ -n "\${ZSH_VERSION}" ]] \&\& echo "\${(P)\1}" || echo "\${!\1}" )/g' \
# -e 's/cur_dir="\$(cd "\$(dirname "\$0")" && pwd)"/cur_dir="\/workspace\/vscode"/' \
# "$_prep_env"
# fi
# # Now source the patched script directly
# source "$_prep_env"
# Set cur_dir before sourcing so prep_env.sh uses the correct path
export cur_dir="/workspace/vscode"
# Patch prep_env.sh for zsh compatibility before sourcing
source <(sed -e 's/^shopt -s histappend$/[[ -n "${BASH_VERSION}" ]] \&\& shopt -s histappend/' \
-e 's/\${!\([^}]*\)}/${(P)\1}/g' \
-e 's/cur_dir="\$(cd "\$(dirname "\$0")" && pwd)"/# cur_dir already set/g' \
/workspace/mlx/../vscode/prep_env.sh)
# sh -c /opt/tiger/mlx_deploy/greeting.sh
if [ -f "/opt/tiger/mlx_deploy/pythonpath_rc" ]; then
source /opt/tiger/mlx_deploy/pythonpath_rc
fi
if [ -f "/opt/tiger/rh2_bashrc" ]; then
source /opt/tiger/rh2_bashrc
fi
. "$HOME/.cargo/env"
# huggingface proxy
export HF_NETWORK_PROXY=http://huggingface-proxy-sg.byted.org
export HF_MIRROR_INTERNAL=http://huggingface-mirror.bytedance.net
export HF_MIRROR_EXTERNAL=https://hf-mirror.com
export HF_ENDPOINT=$HF_NETWORK_PROXY
alias hf_network_proxy='export HF_ENDPOINT=$HF_NETWORK_PROXY'
alias hf_mirror_internal='export HF_ENDPOINT=$HF_MIRROR_INTERNAL'
alias hf_mirror_external='export HF_ENDPOINT=$HF_MIRROR_EXTERNAL'
# http proxy
export HTTP_PROXY=http://sys-proxy-rd-relay.byted.org:8118
export HTTPS_PROXY=http://sys-proxy-rd-relay.byted.org:8118
export NO_PROXY=byted.org,bytedance.net,10.*.*.*,127.*.*.*
export http_proxy=http://sys-proxy-rd-relay.byted.org:8118
export https_proxy=http://sys-proxy-rd-relay.byted.org:8118
export no_proxy=byted.org,bytedance.net,10.*.*.*,127.*.*.*
alias proxy_on='export http_proxy=http://sys-proxy-rd-relay.byted.org:8118; export https_proxy=http://sys-proxy-rd-relay.byted.org:8118; export no_proxy=byted.org,bytedance.net,10.*.*.*,127.*.*.*; export HTTP_PROXY=http://sys-proxy-rd-relay.byted.org:8118; export HTTPS_PROXY=http://sys-proxy-rd-relay.byted.org:8118; export NO_PROXY=byted.org,bytedance.net,10.*.*.*,127.*.*.*'
alias proxy_off='unset http_proxy; unset https_proxy; unset no_proxy; unset HTTP_PROXY; unset HTTPS_PROXY; unset NO_PROXY'

38
zshrc/merlin_worker.zsh Normal file
View File

@@ -0,0 +1,38 @@
# specific aliases
alias save_log=/opt/tiger/rh2/rh2/init/log.sh
alias stdout='tail -f /var/log/tiger/stdout'
alias stderr='tail -f /var/log/tiger/stderr'
# Essential environment variables
export MERLIN_PROFILING_HDFS_DIR='hdfs://haruna/home/byte_merlin_profiling/'
export RH2_ENV_JSON=/opt/tiger/rh2/env_json
export MLX_USER_TOKEN=bd2a3f1b71d54ab497f13f2eefc4f5bc
export RH2_TENSORBOARD_HDFS=hdfs://haruna/home/byte_aml_platform/public/rh2_prod/8b6d8490dc2904e0/tensorboard/20250527/903e5003c90ff1dc/arnold_trial/46714689
export SPARK_HOME=/opt/tiger/spark_deploy/spark-3.2/spark-stable
export PATH=/opt/common_tools:/opt/tiger/typhoon-blade:/usr/lib/x86_64-linux-gnu/openmpi/bin:/usr/local/cuda/bin:/home/tiger/system_op/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/tiger/arnold/arnold_entrypoint/tools:/opt/tiger/arnold/hdfs_client:/opt/tiger/yarn_deploy/hadoop/bin:/opt/tiger/yarn_deploy/hive/bin:/home/tiger/.local/bin:/opt/tiger/nastk/bin:/python:/opt/tiger/mlx_deploy/bin
export PYSPARK_DRIVER_PYTHON=/usr/bin/python3
export PYSPARK_PYTHON=/usr/bin/python3
export PYTHONPATH=::/opt/tiger/arnold_toolbox:/opt/tiger/rh2:/opt/tiger/rh2:/opt/tiger/pyutil:/python:/python/lib/py4j-0.10.9-src.zip
export PATH=/opt/tiger/arnold/arnold_entrypoint/debugger/cloudide/release-standalone/bin/remote-cli:$PATH
export PYTHONPATH=$PYTHONPATH:/opt/tiger/pyutil:/opt/tiger/rh2:/opt/tiger/arnold_toolbox
# huggingface proxy
export HF_NETWORK_PROXY=http://huggingface-proxy-sg.byted.org
export HF_MIRROR_INTERNAL=http://huggingface-mirror.bytedance.net
export HF_MIRROR_EXTERNAL=https://hf-mirror.com
export HF_ENDPOINT=$HF_NETWORK_PROXY
alias hf_network_proxy='export HF_ENDPOINT=$HF_NETWORK_PROXY'
alias hf_mirror_internal='export HF_ENDPOINT=$HF_MIRROR_INTERNAL'
alias hf_mirror_external='export HF_ENDPOINT=$HF_MIRROR_EXTERNAL'
# http proxy
export HF_ENDPOINT=http://huggingface-proxy-sg.byted.org
export HTTP_PROXY=http://sys-proxy-rd-relay.byted.org:8118
export HTTPS_PROXY=http://sys-proxy-rd-relay.byted.org:8118
export NO_PROXY=byted.org,bytedance.net,10.*.*.*,127.*.*.*
export http_proxy=http://sys-proxy-rd-relay.byted.org:8118
export https_proxy=http://sys-proxy-rd-relay.byted.org:8118
export no_proxy=byted.org,bytedance.net,10.*.*.*,127.*.*.*
alias proxy_on='export http_proxy=http://sys-proxy-rd-relay.byted.org:8118; export https_proxy=http://sys-proxy-rd-relay.byted.org:8118; export no_proxy=byted.org,bytedance.net,10.*.*.*,127.*.*.*; export HTTP_PROXY=http://sys-proxy-rd-relay.byted.org:8118; export HTTPS_PROXY=http://sys-proxy-rd-relay.byted.org:8118; export NO_PROXY=byted.org,bytedance.net,10.*.*.*,127.*.*.*'
alias proxy_off='unset http_proxy; unset https_proxy; unset no_proxy; unset HTTP_PROXY; unset HTTPS_PROXY; unset NO_PROXY'

View File

@@ -1,4 +1,7 @@
# Initialize nvm (Node Version Manager)
export NVM_DIR="${XDG_CONFIG_HOME:-$HOME/.nvm}"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
export NVM_DIR="$HOME/.nvm"
nvm() {
unset -f nvm
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
nvm "$@"
}

View File

@@ -242,7 +242,7 @@
# - verbose: Enable instant prompt and print a warning when detecting console output during
# zsh initialization. Choose this if you've never tried instant prompt, haven't
# seen the warning, or if you are unsure what this all means.
typeset -g POWERLEVEL9K_INSTANT_PROMPT=verbose
typeset -g POWERLEVEL9K_INSTANT_PROMPT=off
# Hot reload allows you to change POWERLEVEL9K options after Powerlevel10k has been initialized.
# For example, you can type POWERLEVEL9K_BACKGROUND=red and see your prompt turn red. Hot reload

315
zshrc/prep_env.sh Normal file
View File

@@ -0,0 +1,315 @@
#!/bin/bash
############################################################
# alias
############################################################
alias launch='mlx worker launch'
alias run='launch'
##################
# history
##################
export HISTSIZE=100000
export HISTFILESIZE=200000
# 2. 在关闭终端时追加历史记录,而不是覆盖
[[ -n "${BASH_VERSION}" ]] && shopt -s histappend
# 3. 忽略重复及以空格开头的命令
export HISTCONTROL=ignoreboth
# 4. 忽略特定的常用命令
# export HISTIGNORE="&:[bf]g:exit:pwd:clear:history"
# 5. 为命令添加时间戳
export HISTTIMEFORMAT="%F %T "
# 6. 在每次命令后立即写入历史,实现多终端实时共享
# 注意:这可能会对性能有轻微影响,但对于大多数现代计算机来说可以忽略不计
# export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
##################
# set ulimit
##################
ulimit -n 1024768
############################################################
# 兼容 IGNOREEOF
############################################################
# bash: 连续两次 Ctrl-D 才退出
export IGNOREEOF=2
# zsh: 对应的 setopt
if [[ -n "${ZSH_VERSION}" ]]; then
setopt IGNORE_EOF 2>/dev/null || true
fi
############################################################
# MLX / Merlin 相关环境(从 mlxrc & start_devbox 合并)
############################################################
# Kerberos cache 位置
export KRB5CCNAME="${KRB5CCNAME:-FILE:/opt/tiger/.krb5cc_${UID}}"
# MLX / Notebook 相关 PYTHONPATH
# 在已有 PYTHONPATH 前追加 /mlx/workspace:/tmp/mlx/workspace:/opt/tiger:/opt/tiger/lite_sdk
# 并确保 mlx_notebook_pysdk 路径存在
if [[ -z "${PYTHONPATH}" ]]; then
export PYTHONPATH="/mlx/workspace:/tmp/mlx/workspace:/opt/tiger:/opt/tiger/lite_sdk:/opt/tiger/mlx_notebook_pysdk/mlx-pysdk"
else
export PYTHONPATH="/mlx/workspace:/tmp/mlx/workspace:/opt/tiger:/opt/tiger/lite_sdk:${PYTHONPATH}:/opt/tiger/mlx_notebook_pysdk/mlx-pysdk"
fi
# pyspark 相关
export PYSPARK_PYTHON="${PYSPARK_PYTHON:-/usr/bin/python3}"
export PYSPARK_DRIVER_PYTHON="${PYSPARK_DRIVER_PYTHON:-/usr/bin/python3}"
# 默认 local[2],和原 mlxrc 保持一致
export PYSPARK_SUBMIT_ARGS="${PYSPARK_SUBMIT_ARGS:---master local[2] pyspark-shell}"
# MLXLAB devbox code disk 标记(如果启动脚本已经设置,就不要覆盖)
if [[ -n "${MLXLAB_DEVBOX_CODE_DISK}" ]]; then
export MLXLAB_DEVBOX_CODE_DISK=''
fi
# MLX / Merlin 相关变量(假设在容器启动时已经由 start_devbox.sh 导出)
# 这里统一再 export 一遍,保证交互 shell 也能继承
export MLX_USER_TOKEN='bd2a3f1b71d54ab497f13f2eefc4f5bc'
export MLX_USER='qingyuhao'
export MLX_IMAGE_VID='d51qjdbc77u9kebl603g'
export MLX_IMAGE_URL='hub.byted.org/reckon/data.reckon.mlx.image_10786:4aa09c59c9cbb1fcde50526696177c84'
export MLX_ENGINE_SID='bgi0zldy6943b7db'
export MLX_DEVBOX_ID='132783'
export MLX_HOST_URL='https://ml.bytedance.net/'
export MERLIN_HOST_URL='https://ml.bytedance.net'
export TCC_CDN_HOST='//lf6-config.bytetcc.com/obj/tcc-config-web'
export ZTI_ENV='cn'
export IS_SEED='true'
export MLXLAB_DEVBOX_CODE_DISK=''
# DOAS_ZONE从 BYTE_REGION 推导)
if [[ "${BYTE_REGION}" == "CN" ]]; then
export DOAS_ZONE="cn"
else
export DOAS_ZONE="row"
fi
# SEC_KV_AUTH
export SEC_KV_AUTH=1
# 统一补全 NO_PROXY / no_proxy
# 基础域名列表
_base_no_proxy=".byted.org,byted.org,.bytedance.net,bytedance.net"
for _v in NO_PROXY no_proxy; do
if [[ -n "${BASH_VERSION}" ]]; then
_cur="${!_v}"
else
_cur="${(P)_v}"
fi
if [[ -z "${_cur}" ]]; then
export ${_v}="${_base_no_proxy}"
else
# 如果已经包含基础域名,就不重复追加
if [[ "${_cur}" == *".byted.org"* || "${_cur}" == *".bytedance.net"* ]]; then
export ${_v}="${_cur}"
else
export ${_v}="${_base_no_proxy},${_cur}"
fi
fi
done
unset _v _cur _base_no_proxy
# IS_SEED: 禁用代理(和原来写进 mlxrc 的逻辑保持一致)
if [[ "${IS_SEED}" == "true" ]]; then
unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY
fi
############################################################
# /tmp/krb5cc_0 软链(从 mlxrc 挪过来)
############################################################
if [[ ! -e /tmp/krb5cc_0 && ! -L /tmp/krb5cc_0 ]]; then
ln -s /opt/tiger/.krb5cc_0 /tmp/krb5cc_0 2>/dev/null || true
fi
############################################################
# for hdfs原 prep_env.sh 中的逻辑)
############################################################
if ! grep -q "source import_hdfs_envs.sh" ~/.bashrc 2>/dev/null
then
if command -v import_hdfs_envs.sh > /dev/null 2>&1 && [[ $(which import_hdfs_envs.sh) != *"pyenv/"* ]]; then
source import_hdfs_envs.sh
else
echo "pyenv env, skip hdfs init, please refer to: https://bytedance.larkoffice.com/docx/T9IrdzKRSomwOOxqbUOcRZyLnqh to do hdfs init manually"
fi
fi
############################################################
# 代理相关
############################################################
unset HTTPS_PROXY
############################################################
# 一次性加载 workspace 级别 env
############################################################
if [[ "$WORKSPACE_ENVS_SET" != "1" ]]; then
envfile="/etc/.container_env"
if [[ -f $envfile ]]; then
while IFS= read -r line; do
_varname="${line%%=*}"
if eval "[[ -z \"\${${_varname}+x}\" ]]"; then # env is not set
export "${_varname}=${line#*=}"
fi
done <"$envfile"
unset _varname
fi
if [[ -n "${ZSH_VERSION}" ]]; then
cur_dir="$(cd "$(dirname "$0")" && pwd)"
if [[ "$ARNOLD_WORKSPACE_BUILD_ENV" != "dev" ]]; then
source "$cur_dir"/zsh_hadoop.sh
fi
else
cur_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ "$ARNOLD_WORKSPACE_BUILD_ENV" != "dev" ]]; then
source "$cur_dir"/bash_hadoop.sh
fi
fi
source "$cur_dir"/common_env.sh
# 原来这里设置 PATH=/workspace:$PATH下面会统一 double-check PATH再保证 /workspace 在 PATH 里
export PATH=/workspace:$PATH
# 从 code-server 进来的 WORKSPACE_PASSWORD
if [[ -z "${WORKSPACE_PASSWORD}" ]]; then
export WORKSPACE_PASSWORD="$(ps -ef | grep -oP 'vscode-token\ \K.*' | head -n 1)"
fi
export WORKSPACE_ENVS_SET=1
fi
############################################################
# Double check PATH
# 保证以下目录全部在 PATH 中(合并了原 prep_env.sh + mlxrc 的目录)
############################################################
for i in \
"$HOME/.local/bin" \
"$HOME/bin" \
"/workspace" \
"/usr/local/bvc/bin" \
"/opt/tiger/arnold/bin" \
"/opt/tiger/consul_deploy/bin/go" \
"/opt/tiger/spark_deploy/spark-3.2/spark-stable/bin" \
"/opt/mlx_deploy/miniconda3/envs/mlx/bin" \
"/opt/tiger/mlx_deploy" \
"/opt/tiger/ss_bin" \
"/opt/tiger/ss_lib/bin" \
"/opt/common_tools" \
"/opt/tiger/yarn_deploy/hadoop/bin" \
"/opt/tiger/yarn_deploy/hive/bin"
do
if [[ ":$PATH:" != *":$i:"* ]]; then
PATH="$i:$PATH"
fi
done
# DEVBOX_PATH 单独处理一下(可能是一个长路径)
if [[ -n "${DEVBOX_PATH}" && ":$PATH:" != *":$DEVBOX_PATH:"* ]]; then
PATH="${DEVBOX_PATH}:$PATH"
fi
export PATH
############################################################
# worker 级别 env原 prep_env.sh
############################################################
worker_envfile="/etc/worker_envs_$ARNOLD_WORKER_ID"
user_worker_envfile="$HOME/.worker_envs/worker_envs_$ARNOLD_WORKER_ID"
if [[ -f $user_worker_envfile ]]; then
while IFS= read -r line; do
_varname="${line%%=*}"
if eval "[[ -z \"\${${_varname}+x}\" ]]"; then # env is not set
export "${_varname}=${line#*=}"
fi
done <"$user_worker_envfile"
unset _varname
elif [[ -f $worker_envfile ]]; then
while IFS= read -r line; do
_varname="${line%%=*}"
if eval "[[ -z \"\${${_varname}+x}\" ]]"; then # env is not set
export "${_varname}=${line#*=}"
fi
done <"$worker_envfile"
unset _varname
fi
############################################################
# PS1原 prep_env.sh
############################################################
if [[ -z "${ZSH_VERSION}" ]]; then
if [[ -n "${ARNOLD_WORKER_ID}" ]]; then
export PS1='\[\033[01;32m\]\u@$ARNOLD_WORKER_ID.worker:\W\[\033[00m\]\$ \[\]'
elif [[ -n "${ARNOLD_WORKSPACE_ID}" ]]; then
export PS1='\[\033[01;34m\]\u@$ARNOLD_WORKSPACE_ID.master:\W\[\033[00m\]\$ \[\]'
else
export PS1='\u@\h:\W\$ '
fi
fi
############################################################
# 从 镜像中继承 PYTHONPATH、PATH、LD_LIBRARY_PATH 等关键环境变量
############################################################
envfile="/etc/.env"
env_white_list="PYTHONPATH PATH LD_LIBRARY_PATH" # 需要去重的环境变量列表
# 定义一个函数,用于对冒号分隔的环境变量去重
deduplicate_env() {
local var_value="$1"
echo "$var_value" | awk -v RS=':' '!a[$0]++ {
if (NR > 1) printf(":");
printf("%s", $0)
}'
}
if [[ -f "$envfile" ]]; then
while IFS= read -r line || [[ -n "$line" ]]; do
# 跳过注释行和空行
[[ "$line" =~ ^[[:space:]]*# ]] && continue
[[ "$line" =~ ^[[:space:]]*$ ]] && continue
# 提取变量名和值
var_name="${line%%=*}"
var_value="${line#*=}"
# 检查变量名是否有效
[[ "$var_name" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] || continue
if [[ " $env_white_list " == *" $var_name "* ]]; then
# 变量已设置且在白名单中,追加新值并去重
if [[ -n "${BASH_VERSION}" ]]; then
existing_value="${!var_name}"
else
existing_value="${(P)var_name}"
fi
if [[ -n "$existing_value" ]]; then
new_value="$var_value:$existing_value"
dedup_value=$(deduplicate_env "$new_value")
export "$var_name=$dedup_value"
else
export "$var_name=$var_value"
fi
fi
done <"$envfile"
fi
############################################################
# GPU 相关(原 prep_env.sh
############################################################
if [[ -n $NVIDIA_VISIBLE_DEVICES && $NVIDIA_VISIBLE_DEVICES != 'none' ]]; then
if [[ -n "${ZSH_VERSION}" ]]; then
cur_dir="$(cd "$(dirname "$0")" && pwd)"
else
cur_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
fi
source "$cur_dir"/nvidia.sh
fi

4
zshrc/pyenv.zsh Normal file
View File

@@ -0,0 +1,4 @@
# Initialize pyenv (Python Version Manager)
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH" # Add pyenv to PATH
eval "$(pyenv init - zsh)" # This loads pyenv