## 安装zsh
使用ubuntu的话,使用apt安装即可`sudo apt install zsh`安装完成后,可以通过`zsh --version`检查是否安装成功,接着使用`chsh -s $(which zsh)`将zsh设置为默认shell。然后重新打开一个新的终端,使用`echo $SHELL`可以检查当前的shell
类型是否是zsh。如果是其他的操作系统也可以参考onmyzsh wiki上的详细教程
[onmyzsh wiki install zsh](https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH)
## 安装ohmyzsh
请提前确保你安装了curl或者wget这两个可以通过`sudo apt install curl`和`sudo apt install wget`安装
ohmyzsh官方提供了自动安装脚本,可以通过curl或wget安装:
`sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"`
`sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"`
如果无法访问github,也可以使用国内镜像:
`sh -c "$(wget -O- https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"`
## ohmyzsh主题配置及推荐
有关zsh主题可以编辑~/.zshrc文件找到ZSH_THEME行,修改其值为你喜欢的主题名称例如:`ZSH_THEME=robbyrussell`保存文件,然后重新source ~/.zshrc一下相关主题可以通过下面这个链接查看
[zsh 主题](https://github.com/ohmyzsh/ohmyzsh/wiki/External-themes)
这里我比较推荐的主题是powerlevel10k这个主题因为需要使用额外的符号,所有需要安装额外的字体NerdFont不同系统的安装方法,可查看[它的文档](https://github.com/ryanoasis/nerd-fonts#font-installation)
这里写一下wsl的安装方法
在powershell中通过以下三条命令可以安装
`Install-PSResource -Name NerdFonts`
`Import-Module -Name NerdFonts`
`Install-NerdFont -Name 'FiraCode'`
安装完成后,重启powershell,在设置默认值里更改字体即可。
接着安装powerlevel10k使用下面的命令下载`git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k`编辑.zshrc`ZSH_THEME="powerlevel10k/powerlevel10k"``source ~/.zshrc`source一下进入配置界面回答完一系列问题后就配置好了
配置完成后如果想要重新配置可以用`p10k configure`重新配置
## ohmyzsh插件配置及推荐
这里我比较常用的有以下这三个:
- zsh-autosuggestions:命令自动建议
- zsh-syntax-highlighting:语法高亮
- zsh-completions:补全增强
`git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions`
`git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting`
`git clone --depth=1 https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-completions`
然后修改 ~/.zshrc,添加插件:
`plugins=(git zsh-autosuggestions zsh-completions zsh-syntax-highlighting)`
最后source一下使配置生效
`source ~/.zshrc`
如果想要添加一些其他插件就在括号里面继续添加即可,记得插件之间要用空格隔开可以在[这里](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins)找到一些官方自带的插件。
最后再分享一个我在写博客查找资料过程看到的一个终端查找历史命令的快捷键先输入ctrl+R,然后通过以前命令的一部分去匹配以前的命令。
还有提醒一下:.zshrc文件和 ~/.oh-my-zsh文件夹要记得备份。