🧩 在 Ubuntu 下配置 oh-my-posh —— 普通用戶 + root 各自使用獨立主題(共享可執行)
? 目標說明
- 普通用戶 使用
tokyonight_storm
主題 - root 用戶 使用
1_shell
主題 - 共用全局路徑下的
oh-my-posh
可執行文件 - 正確加載 Homebrew 到環境變量中
- 分別加載獨立的
.omp.json
配置 ?
🔧 安裝流程
🧱 1. 安裝 Homebrew(普通用戶下)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
🛠? 2. 將 Brew 加入環境變量(寫入 .bashrc
)
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc
source ~/.bashrc
📌 如果你使用 zsh
,請改為 .zshrc
🧠 3. Nerd Font 字體設置(終端圖標支持)
Ubuntu 本地終端
mkdir -p ~/.local/share/fonts/NerdFonts
cd ~/.local/share/fonts/NerdFontswget https://github.com/ryanoasis/nerd-fonts/releases/download/v3.1.1/FiraCode.zip
unzip FiraCode.zip
rm FiraCode.zipfc-cache -fv
WSL2 設置方法
-
打開 Windows Terminal → 選擇配置的 profile
-
Appearance(外觀)
→ Font → 設置為FiraCode Nerd Font
等
📦 4. 安裝 oh-my-posh
brew install jandedobbeleer/oh-my-posh/oh-my-posh
如遇編譯錯誤提示:
sudo apt install clang
🪛 5. 將 oh-my-posh
拷貝至全局路徑
sudo cp $(which oh-my-posh) /usr/local/bin/
sudo chmod +x /usr/local/bin/oh-my-posh
🎨 6. 下載全部主題文件(需先裝 unzip)
sudo apt install unzip -ymkdir -p ~/.poshthemes
cd ~/.poshthemescurl -fLo themes.zip https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip
unzip themes.zip
chmod 644 *.omp.json
rm themes.zip
👤 普通用戶配置(使用 tokyonight_storm)
🪛 編輯 ~/.bashrc
nano ~/.bashrc
加入:
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
eval "$(oh-my-posh init bash --config ~/.poshthemes/tokyonight_storm.omp.json)"
保存并生效:
source ~/.bashrc
👑 root 用戶配置(使用 1_shell)
📁 拷貝主題文件到 root
sudo mkdir -p /root/.poshthemes
sudo cp ~/.poshthemes/1_shell.omp.json /root/.poshthemes/
sudo chmod 644 /root/.poshthemes/1_shell.omp.json
🪛 編輯 /root/.bashrc
sudo nano /root/.bashrc
添加:
eval "$(oh-my-posh init bash --config /root/.poshthemes/1_shell.omp.json)"
保存并生效:
sudo su
source ~/.bashrc
? 總結配置表
組件 | 內容 | 路徑或值 |
---|---|---|
Brew | 環境變量加載 | /home/linuxbrew/.linuxbrew/bin/brew shellenv |
oh-my-posh | 全局可執行文件 | /usr/local/bin/oh-my-posh |
普通用戶 | 使用 tokyonight_storm 主題 | ~/.poshthemes/tokyonight_storm.omp.json |
root 用戶 | 使用 1_shell 主題 | /root/.poshthemes/1_shell.omp.json |
🎉 你現在已經完成了 oh-my-posh 的完整配置 🎨