利器之ZSH

有些工具真的很能提高效率, 比如oh-my-zsh这个扩展(zsh本身比bash更强大).

纵观软件世界,一个软件系统能流行起来很大原因是其生态是不是够丰富和繁荣,比如容器docker,Spring框架.

oh-my-zsh提供了丰富的插件及主题,是我的装机必备. 在这里记录下常用设置.

安装及扩展

安装zsh和on-my-zsh

sudo apt install zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

安装插件

# Mac
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-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# Ubuntu
sudo apt install zsh-syntax-highlighting  autojump
# Mac 
brew install zsh-syntax-highlighting autojump

更友好的显示

使用powerline

sudo apt install powerline
# 或者用pip安装
pip install --user powerline-status

Mac设置:

iTerm2 - [Preferences] - [Profiles] - [Text] - 勾选“Use built-in Powerline glyphs”

Windows设置:

git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
# 以管理员身份打开powershell
./install.ps1

常用配置

根据偏好修改 ~/.zshrc

# 我喜欢的主题 agnoster
ZSH_THEME="agnoster"
# 常用插件, git和autojump必备
# Mac下应该去掉 zsh-syntax-highlighting, 因为它被brew安装在其他路径下
plugins=(git autojump git-flow git-extras python sudo extract zsh-syntax-highlighting zsh-autosuggestions)
# 配置默认用户
DEFAULT_USER=xulz
# 更新PATH
export PATH=/home/xulz/.local/bin:$PATH

常用命令

# 重新加载配置以生效
source ~/.zshrc
# 更新默认shell为zsh
chsh -s /bin/zsh

缩短路径显示

如果文件路径层级较多,显示路径比较占视野. 可以修改为:

# 
cd  ~/.oh-my-zsh/themes
cp agnoster.zsh-theme xulz.zsh-theme
vi xulz.zsh-theme
# 修改 prompt_dir()方法
prompt_dir() {
  # 如果路径超过5个层级,只显示最后2级目录, Home显示为~
  prompt_segment 39d $CURRENT_FG '%(5~|%-1~/.../%2~|%4~)'
}