安装zsh
安装之前可以查看当前系统下的可用shell
cat /etc/shells
然后使用命令安装zsh
sudo apt install zsh
这时再查看/etc/shells
就会发现已经有了zsh这个shell
输入命令如下:
zsh
出现如下界面
输入数字2,然后回车
使用oh-my-zsh配置zsh
oh-my-zsh是大佬封装好的zsh配置,直接用就完事了。
首先将项目down到本地的~/.oh-my-zsh
中
git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
使用模板替换,zsh自带的配置文件
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
让新的配置文件生效
source ~/.zshrc
在.zshrc
中选择自己喜欢的主题,所有的主题都在这里
我选择了ys这种样式,修改.zshrc 中的ZSH_THEME
变量的引号内内容即可
关闭终端重新进入发现还是在bash下,不要慌
使用zsh
命令之后,使用命令修改默认终端
chsh -s /bin/zsh
然后重启电脑或者,logout进入ubuntu后,打开终端就是我们想要的zsh样式啦。
添加插件
oh-my-zsh 的自带插件都储存在~/.oh-my-zsh/plugins
目录中,如果你希望安装一个插件,可以在 “~/.zshrc” 的 plugins=(xxx xxx …) 这一行里加入插件名称
这里我们配置两个第三方插件,语法高亮和命令提示插件
语法高亮
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh}/plugins/zsh-syntax-highlighting
命令提示
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh}/plugins/zsh-autosuggestions
然后修改.zshrc
plugins=(git zsh-syntax-highlighting zsh-autosuggestions)
再让配置文件生效,效果如下:
遇到的问题:
yang@saviour$ source ~/.zshrc
-bash: autoload: command not found
-bash: /Users/hank/.oh-my-zsh/oh-my-zsh.sh: line 41: syntax error near unexpected token `('
-bash: /Users/hank/.oh-my-zsh/oh-my-zsh.sh: line 41: `for plugin($plugins); do'
这是因为在bash环境下操作的原因,按照下面的步骤即可解决
zsh
chsh -s $(which zsh)
或者chsh -s /bin/zsh
Logout from the system and login
Run terminal
骤即可解决
zsh
chsh -s $(which zsh)
或者chsh -s /bin/zsh
Logout from the system and login
Run terminal