在 Ubuntu 下配置 oh-my-posh —— 普通用户 + root 各自使用独立主题(共享可执行)

🧩 在 Ubuntu 下配置 oh-my-posh ------ 普通用户 + root 各自使用独立主题(共享可执行)


✅ 目标说明

  • 普通用户 使用 tokyonight_storm 主题
  • root 用户 使用 1_shell 主题
  • 共用全局路径下的 oh-my-posh 可执行文件
  • 正确加载 Homebrew 到环境变量中
  • 分别加载独立的 .omp.json 配置 ✅

🔧 安装流程


🧱 1. 安装 Homebrew(普通用户下)

bash 复制代码
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

🛠️ 2. 将 Brew 加入环境变量(写入 .bashrc

bash 复制代码
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc
source ~/.bashrc

📌 如果你使用 zsh,请改为 .zshrc


🧠 3. Nerd Font 字体设置(终端图标支持)

Ubuntu 本地终端
bash 复制代码
mkdir -p ~/.local/share/fonts/NerdFonts
cd ~/.local/share/fonts/NerdFonts

wget https://github.com/ryanoasis/nerd-fonts/releases/download/v3.1.1/FiraCode.zip
unzip FiraCode.zip
rm FiraCode.zip

fc-cache -fv
WSL2 设置方法
  • 打开 Windows Terminal → 选择配置的 profile

  • Appearance(外观) → Font → 设置为 FiraCode Nerd Font


📦 4. 安装 oh-my-posh

bash 复制代码
brew install jandedobbeleer/oh-my-posh/oh-my-posh

如遇编译错误提示:

bash 复制代码
sudo apt install clang

🪛 5. 将 oh-my-posh 拷贝至全局路径

bash 复制代码
sudo cp $(which oh-my-posh) /usr/local/bin/
sudo chmod +x /usr/local/bin/oh-my-posh

🎨 6. 下载全部主题文件(需先装 unzip)

bash 复制代码
sudo apt install unzip -y

mkdir -p ~/.poshthemes
cd ~/.poshthemes

curl -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

bash 复制代码
nano ~/.bashrc

加入:

bash 复制代码
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
eval "$(oh-my-posh init bash --config ~/.poshthemes/tokyonight_storm.omp.json)"

保存并生效:

bash 复制代码
source ~/.bashrc

👑 root 用户配置(使用 1_shell)

📁 拷贝主题文件到 root

bash 复制代码
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

bash 复制代码
sudo nano /root/.bashrc

添加:

bash 复制代码
eval "$(oh-my-posh init bash --config /root/.poshthemes/1_shell.omp.json)"

保存并生效:

bash 复制代码
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 的完整配置 🎨

相关推荐
鑫宝的学习笔记17 分钟前
Vmware虚拟机联网问题,显示:线缆已拔出!!!
人工智能·ubuntu
半梦半醒*1 小时前
nginx反向代理和负载均衡
linux·运维·nginx·centos·tomcat·负载均衡
喜欢你,还有大家1 小时前
集群的概述和分类和负载均衡集群
运维·负载均衡
liu****1 小时前
负载均衡式的在线OJ项目编写(六)
运维·c++·负载均衡·个人开发
青草地溪水旁2 小时前
pthread_create详解:打开多线程编程的大门
linux·c/c++
Elastic 中国社区官方博客3 小时前
CI/CD 流水线与 agentic AI:如何创建自我纠正的 monorepos
大数据·运维·数据库·人工智能·搜索引擎·ci/cd·全文检索
A-刘晨阳3 小时前
Linux安装centos8及基础配置
linux·运维·服务器·操作系统·centos8
恒雨田3 小时前
解决 jenkins 用户 SSH 连接目标服务器时的 Permission denied 问题
运维·ssh·jenkins
不老刘3 小时前
macOS/Linux ClaudeCode 安装指南及 Claude Sonnet 4.5 介绍
linux·macos·ai编程·claude·vibecoding
迎風吹頭髮4 小时前
UNIX下C语言编程与实践14-UNIX 文件系统格式化:磁盘分区与文件系统创建原理
运维·c语言·unix