1、安装 zsh
macOS:
mac自带zsh,通过homebrew安装即可
brew install zsh
ubuntu:
这里我只尝试了ubuntu,Debian同样可以通过apt-get进行安装
sudo apt-get install zsh
使用 cat /etc/shells
查看系统可以用的 shell
使用 chsh -s /bin/zsh
更改系统默认 shell
2、安装 oh-my-zsh
sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
3、配置 oh-my-zsh
vim ~/.zshrc
#找到这一行修改
ZSH_THEME="要修改的主题名称"
刚安装好zsh后,prompt光秃秃的不好看
PROMPT='%F{green}%n@%m:%~%# %f'PROMPT='%F{green}%n@%m:%~$ %f'
最后,执行 source ~/.zshrc 配置生效
source ~/.zshrc
4、配置提示
下载插件以下插件 放到~/.oh-my-zsh/custom/plugins 下
zsh-syntax-highlighting
zsh-autosuggestions
zsh-completions
zsh-history-substring-search
git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-completions
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
配置提示:在~/.zshrc添加如下信息,默认只有git
plugins=(git
zsh-syntax-highlighting
zsh-autosuggestions
zsh-completions
zsh-history-substring-search)source $ZSH/oh-my-zsh.sh
5、解决Bash切换Zsh后,bashrc文件失效
Add two lines code to your ~/.zshrc
, zsh will autorun your customized commands in .bashrc
.
# Exec ~/.bashrc and ~/.profile when using zsh
if [ -f '~/.profile' ]; then; source '~/.profile'; fi;
source <(awk '{ if(NR>118)print}' ~/.bashrc)
# Line 118 is works for Ubuntu's default .bashrc
Once done then run:
source ~/.zshrc
参考:zsh - How can you export your .bashrc to .zshrc? - Stack Overflow