OMZ 美化
3 年前(已编辑)
/ ,
77
1
这篇文章上次修改于 1 年前,可能部分内容已经不适用,如有疑问可询问作者。
仅支持 MacOS / Linux / WSL
由于经常折腾开发环境,将 shell 美化过程记录一下,方便以后查阅。
效果图:

一、安装 oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
安装成功后,之前的 .zshrc
文件会被重命名为 .zshrc.pre-oh-my-zsh
,你需要将 shell 配置迁移到新的 .zshrc
。
二、安装 spaceship 主题
1. 克隆仓库
git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt" --depth=1
2. 链接主题目录至 oh-my-zsh
ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"
3. 编辑 .zshrc
ZSH_THEME="spaceship"
SPACESHIP_TIME_SHOW="true" # 显示时间
SPACESHIP_USER_SHOW="always" # 显示用户名
SPACESHIP_USER_COLOR="212" # 猛男粉配色
三、安装插件
1. autojump
这个插件会根据输入的关键字进行目录联想,假设在某一时刻进入过 ~/work/test
目录。当你在终端输入 j te
时,插件会进行联想,匹配到 ~/work/test
目录,然后进入。
安装
MacOS
brew install autojump
Debian / Ubuntu
sudo apt install autojump
修改
.zshrc
,在plugins
中添加autojump
plugins=( git autojump )
2. zsh-autosuggestions
输入命令时,终端会自动提示你接下来可能要输入的命令,这时按下方向右键 →
便可输出这些命令,非常方便。
安装
git clone https://gitee.com/phpxxo/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
修改
.zshrc
,在plugins
中添加plugins=( git autojump zsh-autosuggestions )
3. zsh-syntax-highlighting
输入命令时,错误的命令将显示为红色,正确的命令显示为绿色。
安装
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
修改
.zshrc
,在plugins
中添加plugins=( git autojump zsh-autosuggestions zsh-syntax-highlighting )