Linux 终端的一些配置(macOS 也适用),令你的Terminal更好用,更美观。
-
首先安装
zshsudo apt install zsh(以Ubuntu为例)或者用过源码安装如果没有root权限,通过源码安装,下载解压之后:
1
2
3
4
5
6
7
8
9
10
11# 首先配置zsh,自定义安装路径 ./configure --prefix=$HOME/.local # 然后编译 make -j4 # 检查编译是否成功(可选) make check # 如果没有编译错误,则安装zsh make install -j4源码安装完成后,将执行路径加入PATH中。在文件
.bash_profile中最后加上export PATH=$HOME/.local/bin:$PATH -
将zsh设置为默认shell
如果使用root权限安装的zsh,直接终端运行
chsh -s $(which zsh)即可。如果没有root权限,通过源码安装zsh的话,则解决方法是在每次打开终端时执行
exec <zsh-path>来替代当前的shell。在文件.bash_profile中加入:1
[ -f $HOME/.local/bin/zsh ] && exec $HOME/.local/bin/zsh -l如果上述两种方法都不能修改默认shell,直接跳到第 3 步,安装
oh-my-zsh,安装时会自动切换shell成zsh。 -
安装
oh-my-zsh通过curl
1
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"或者通过wget
1
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"如果上述方法出现问题,可以按照下面的方法进行:
1
2
3
4cd git clone https://github.com/robbyrussell/oh-my-zsh.git mv oh-my-zsh .oh-my-zsh cp .oh-my-zsh/template/zshrc.zsh-template ~/.zshrc -
配置
oh-my-zshvim .zshrc,切换ZSH_THEME,可以在这里预览。想要隐藏用户名,
export DEFAULT_USER="<user-name>"插件配置(精髓)
在
.zshrc中找到plugins=(git),其中加入以下插件:1
2
3
4
5
6
7plugins=( git extract # 一个命令 `x` 解压全部压缩文件 z # cd的加强版,到达任意到过的位置,模糊匹配 zsh-syntax-highlighting # 指令高亮 zsh-autosuggestions # 命令自动提示,方向键补全 )其中插件
zsh-syntax-highlighting和zsh-autosuggestions需要单独下载,方法如下:1
2
3
4
5# 下载zsh-syntax-highlighting git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting # 下载zsh-autosuggestions git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions -
配置
powerline-theme下载字体:
1
2
3
4
5
6
7
8# clone git clone https://github.com/powerline/fonts.git --depth=1 # install cd fonts ./install.sh # clean-up a bit cd .. rm -rf fonts然后选择
oh-my-zsh中powerline相关主题即可。 -
下载
powerline-status(可选)1
2
3
4
5
6
7
8
9# pip安装powerline-status pip install powerline-status # 获得powerline-status安装路径 pip show powerline-status # 配置到.zshrc文件中,在末尾添加 # 注意.后面有一个空格 . /Powerline安装路径/powerline/bindings/zsh/powerline.zsh安装
powerline-gitstatus,配置 Git Branch Info 的显示。1
pip install powerline-gitstatus然后直接修改
powerline的配置文件或者创建~/.config/powerline并复制一份配置,1
cp -r /path/to/powerline/config_files/* ~/.config/powerline在
~/.config/powerline/colorschemes/default.json中添加group:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16"groups": { "gitstatus": { "fg": "gray8", "bg": "gray2", "attrs": [] }, "gitstatus_branch": { "fg": "gray8", "bg": "gray2", "attrs": [] }, "gitstatus_branch_clean": { "fg": "green", "bg": "gray2", "attrs": [] }, "gitstatus_branch_dirty": { "fg": "gray8", "bg": "gray2", "attrs": [] }, "gitstatus_branch_detached": { "fg": "mediumpurple", "bg": "gray2", "attrs": [] }, "gitstatus_tag": { "fg": "darkcyan", "bg": "gray2", "attrs": [] }, "gitstatus_behind": { "fg": "gray10", "bg": "gray2", "attrs": [] }, "gitstatus_ahead": { "fg": "gray10", "bg": "gray2", "attrs": [] }, "gitstatus_staged": { "fg": "green", "bg": "gray2", "attrs": [] }, "gitstatus_unmerged": { "fg": "brightred", "bg": "gray2", "attrs": [] }, "gitstatus_changed": { "fg": "mediumorange", "bg": "gray2", "attrs": [] }, "gitstatus_untracked": { "fg": "brightestorange", "bg": "gray2", "attrs": [] }, "gitstatus_stashed": { "fg": "darkblue", "bg": "gray2", "attrs": [] }, "gitstatus:divider": { "fg": "gray8", "bg": "gray2", "attrs": [] } }再根据本人喜好在
~/.config/powerline/colorschemes/default.json的left或right中增加:1
2
3
4{ "function": "powerline_gitstatus.gitstatus", "priority": 40 }并删除
vcs.stash和vcs.branch的相关配置,因为它们和powerline_gitstatus冲突。其他关于powerline_gitstatus的配置可以参见此处。 -
oh-my-zsh主题推荐robbyrussell,agnoster,lambda等。