zsh安装与自定义主题
Zsh(Z-shell)
是一款用于交互式使用的shell
,也可以作为脚本解释器来使用。其包含了bash
,ksh
,tcsh
等其他shell
中许多优秀功能,也拥有诸多自身特色。 从
macOS Catalina
版开始,其默认shell
从bash
改为zsh
。
zsh的安装及配置
- 安装zsh (出错的话更新安装包)
sudo apt install zsh
- 修改默认shell为zsh
chsh -s /bin/zsh
- 安装oh-my-zsh
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
##如果不成功,请执行下面两条命令,成功了就不需要做下面两条
wget 47.93.11.51:88/install_zsh.sh
bash install_zsh.sh
//有可能缺git
//输入git 按提示安装即可
- 安装zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
##有可能出现卡顿 可以ctrl + c结束,重复试几次
- 使用命令
vim .zshrc
打开.zshrc文件,找到plugins=()
这一行,将zsh-syntax-highlighting添加进去
plugins=(git zsh-syntax-highlighting)
- 安装其他插件
##命令自动补全插件
mkdir ~/.oh-my-zsh/plugins/incr
wget http://mimosa-pudica.net/src/incr-0.2.zsh -O ~/.oh-my-zsh/plugins/incr/incr.plugin.zsh
##命令自动推荐,根据历史记录
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
##目录自动跳转插件
sudo apt install autojump
- 使用命令
vim .zshrc
,打开后在最后插入以下内容:
autoload -U colors && colors
PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m "
RPROMPT="[%{$fg[yellow]%}%?%{$reset_color%}]"
PROMPT+="%(?:%{$fg_bold[green]%}✔ :%{$fg_bold[red]%}✗ )"
PROMPT+='%{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
# # Useful support for interacting with Terminal.app or other terminal programs
[ -r "/etc/zshrc_$TERM_PROGRAM" ] && . "/etc/zshrc_$TERM_PROGRAM"
source ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh
source /usr/share/autojump/autojump.sh
source ~/.oh-my-zsh/plugins/incr/incr*.zsh
注意,复制后可能会因为Vim的配置导致以上内容被注释,也就是在前面加上了
#
,如果有的话,删掉就行。
source ~/.zshrc
主题效果
用户名 @ 主机 上一条命令提示 路径名
涉及 git
的,还可以显示分支名,以及如果还有未上传的文件(working tree not clean) 会提示×