ZSH 安装配置

1. 安装基本工具

sudo apt install zsh git curl -y

设置默认终端为 zsh(注意:不要使用 sudo)。

chsh -s /bin/zsh

2. 安装 oh-my-zsh

sh -c "$(curl -fsSL https://install.ohmyz.sh/)"

5. 启用插件

修改~/.zshrc中的主题为:

ZSH_THEME="powerlevel10k/powerlevel10k"

3. 安装 p10k

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

4. 安装插件

4.1 zsh -autosuggestions

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

4.2 zsh-syntax-highlighting

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

5. 启用插件

修改~/.zshrc中插件列表为:

plugins=(git zsh-autosuggestions zsh-syntax-highlighting z extract web-search)

6. 安装字体

p10k 推荐字体

https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf
https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf
https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf
https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf

7. 设置字体

7.1 VSCode

Visual Studio Code :打开文件 → 首选项 → 设置 (PC)或 代码 → 偏好设置 → 设置 (Mac),在 “设置”选项卡顶部的搜索框中输入 terminal.integrated.fontFamily ,并将下面的值设置为 "MesloLGS NF"。

7.2 GNOME 终端

GNOME 终端 (默认的 Ubuntu 终端):打开 “终端”→“首选项” ,然后点击 “配置文件” 下选定的配置文件。勾选 “文本外观” 下的 “自定义字体” ,然后选择 "MesloLGS NF Regular"。

8. 安装脚本

#!/usr/bin/env bash
set -e

USER_HOME="$HOME"
ZSHRC="$USER_HOME/.zshrc"
ZSH_CUSTOM="$USER_HOME/.oh-my-zsh/custom"
FONT_DIR="$USER_HOME/.local/share/fonts"

echo "👉 [1/8] 安装 zsh 及依赖..."
if command -v sudo >/dev/null 2>&1; then
    sudo apt-get update && sudo apt-get install -y zsh git curl wget locales fonts-powerline
else
    echo "⚠️  未检测到 sudo,请先以 root 安装 zsh、git、curl、wget、locales、fonts-powerline。"
fi

echo "👉 [2/8] 设置本地语言环境..."
if command -v sudo >/dev/null 2>&1; then
    sudo locale-gen en_US.UTF-8
fi
export LANG=en_US.UTF-8
export LANGUAGE=en_US:en
export LC_ALL=en_US.UTF-8

echo "👉 [3/8] 安装 Oh My Zsh..."
export RUNZSH=no
export CHSH=no
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

echo "👉 [4/8] 安装 Powerlevel10k 主题..."
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$ZSH_CUSTOM/themes/powerlevel10k"
sed -i 's|^ZSH_THEME=.*|ZSH_THEME="powerlevel10k/powerlevel10k"|' "$ZSHRC"

echo "👉 [5/8] 安装 zsh-autosuggestions 和 zsh-syntax-highlighting 插件..."
git clone https://github.com/zsh-users/zsh-autosuggestions "$ZSH_CUSTOM/plugins/zsh-autosuggestions"
git clone https://github.com/zsh-users/zsh-syntax-highlighting "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"

echo "👉 [6/8] 启用插件..."
sed -i 's/^plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting z extract web-search)/' "$ZSHRC"

echo "👉 [7/8] 安装 MesloLGS NF 字体..."
mkdir -p "$FONT_DIR"
cd "$FONT_DIR"
wget -q https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf
wget -q https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf
wget -q https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf
wget -q https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf
fc-cache -fv

echo "👉 [8/8] 设置登录时自动切换到 zsh(非 root 用户)..."
BASHRC="$USER_HOME/.bashrc"
if ! grep -q "exec zsh" "$BASHRC"; then
    echo "exec zsh" >> "$BASHRC"
fi

echo "✅ 安装完成!"
echo "👉 退出终端重新登录,或者执行:exec zsh"
posted @ 2025-10-03 22:28  BlueSpace  阅读(17)  评论(0)    收藏  举报