oh my zsh

修改默认 shell

用如下命令检查或修改当前 shell(MacOS 默认就是 zsh):

1
2
3
cat /etc/shells   # 查看现有 shell
echo $SHELL # 查看当前 shell
chsh -s /bin/zsh # 修改默认 shell 为 zsh

下载安装 ohmyzsh

官网:https://ohmyz.sh/

GitHub:https://github.com/ohmyzsh/ohmyzsh

1
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

编辑 zsh 配置文件

1
vim ~/.zshrc

个人常用配置在 https://github.com/xyfJASON/rc/blob/main/.zshrc 中维护。

使配置生效:

1
source ~/.zshrc  # 或者直接新开一个 shell

主题

自带主题

ohmyzsh 自带很多主题,可以在 ~/.oh-my-zsh/themes 下查看。

要更换主题,直接修改 ~/.zshrc 中 ZSH_THEME 字段即可,例如:

1
ZSH_THEME="steeef"

powerlevel10k

GitHub: https://github.com/romkatv/powerlevel10k

下载安装

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

设置主题:修改 ~/.zshrc 中 ZSH_THEME 字段。

1
ZSH_THEME="powerlevel10k/powerlevel10k"

第一次启动后会自动运行设置引导,输入 p10k configure 手动运行设置引导。

插件

z (ohmyzsh 自带)

文档https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/z

介绍:ohmyzsh 自带插件,快速跳转到访问过的目录。

添加 plugins:在 ~/.zshrc 中将 z 添加到 plugins 字段中。

1
plugins=(... z)

sublime (ohmyzsh 自带)

文档https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/sublime

介绍:ohmyzsh 自带插件,使用 Sublime Text 打开文件。

添加 plugins:在 ~/.zshrc 中将 sublime 添加到 plugins 字段中。

1
plugins=(... sublime)

使用方法

  • st:打开 Sublime Text.
  • st <file/directory>:使用 Sublime Text 打开文件或目录。
  • stt:使用 Sublime Text 打开当前目录。

zsh-autosuggestions

GitHub: https://github.com/zsh-users/zsh-autosuggestions

下载安装

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

添加 plugins:在 ~/.zshrc 中将 zsh-autosuggestions 添加到 plugins 字段中。

1
plugins=(... zsh-autosuggestions)

zsh-syntax-highlighting

GitHub: https://github.com/zsh-users/zsh-syntax-highlighting

下载安装

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

添加 plugins:在 ~/.zshrc 中将 zsh-syntax-highlighting 添加到 plugins 字段中,注意放在最后一个。

1
plugins=(... zsh-syntax-highlighting)

oh my zsh
https://xyfjason.github.io/blog-main/2023/12/31/oh-my-zsh/
作者
xyfJASON
发布于
2023年12月31日
许可协议