前备工作:
yum -y install zsh / apt install zsh
chsh -s /bin/zsh
安装oh my zsh
- 打开官网:https://ohmyz.sh/ 或 Github页面:https://github.com/ohmyzsh/ohmyzsh
- 找到安装命令
$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
- 如果出现 443 等网络问题
访问下面地址,得到ip地址,追加进 hosts 文件即可(github的可一并加上)
https://ipaddress.com/website/raw.githubusercontent.com
https://ipaddress.com/website/www.github.com
我的最终结果为:
185.199.108.133 raw.githubusercontent.com
140.82.113.4 github.com
- 安装完成后修改主题为 agnoster,编辑
.zshrc
大概11行左右
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
# ZSH_THEME="robbyrussell"
ZSH_THEME="agnoster"
关闭oh my zsh自动更新
- 编辑
.zshrc
找到27行左右,带有 # disable automatic updates,去掉注解
# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled # disable automatic updates
变为:
# Uncomment one of the following lines to change the auto-update behavior
zstyle ':omz:update' mode disabled # disable automatic updates
- 手动更新命令
$ omz update
修改主题
- 变更格式
vim .oh-my-zsh/themes/agnoster.zsh-theme
大概在92行, 或搜索: prompt_context()
### Prompt components
# Each component will draw itself, and hide itself if no information needs to be shown
# Context: user@hostname (who am I and where am I)
prompt_context() {
if [[ "$USERNAME" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
# prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"
prompt_segment black default "%(!.%{%F{yellow}%}.)%n"
fi
}
去掉@%m, 可以省略机器名
- 变更颜色
上面的 prompt_segment black default "%(!.%{%F{yellow}%}.)%n"
可以修改 back 和 default 和 yellow, 来改变配色
插件
- oh-my-zsh 中有内置有很多插件,使用命令vim ~/.zshrc打开,找到 plugins 添加下面的内容
plugins=(
git
extract
z
zsh-syntax-highlighting
zsh-autosuggestions
)
# extract 用于解压任何压缩文件,不必根据压缩文件的后缀名来记忆压缩软件
# z 可以直接跳转到曾经去过的文件夹,在项目多的时候非常实用,之前在 mac 上使用的 autojump,后面发现 zsh 内置的插件 z 也能达到同样的效果
- 剩下两款插件需额外添加
# git clone https://gitee.com/whereabouts-fork/zsh-autosuggestions.git ~/.oh-my-zsh//plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/plugins/zsh-autosuggestions
# git clone https://gitee.com/whereabouts-fork/zsh-syntax-highlighting.git ~/.oh-my-zsh//plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting
- 最后运行
source ~/.zshrc
- 另一种方式
brew install zsh-autosuggestions
brew install zsh-syntax-highlighting
echo "source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc
echo "source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc
- 配置后
.zshrc
效果
....
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh