1. Oh My Zsh是什么

Oh My Zsh是一个开源的、社区驱动的框架,用于管理zsh 配置。让天下没有难用的终端(Terminal), 终端terminal神器.

适用于Mac Linux平台.

2. Oh My Zsh安装, Oh My Zsh官网

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

3. Oh My Zsh插件, Git zsh-autosuggestions fasd zsh-syntax-highlighting 让终端起飞.

3.1 Git插件, Oh My Zsh自带, 把所有的git命令做了别名, 更快使用git命令.

在~/.zshrc中启用

plugins=(git)
# 终端内
# gb 等于 git branch
# st 等价git status
# gcmsg 等于 git commit -m
# gm 等于git merge
# gco 等于git checkout

全部别名地址

3.2 zsh-autosuggestions 显示之前运行的命令, 按<control + e>即可补全.

zsh-autosuggestions安装官网

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
plugins=(git zsh-autosuggestions)
sourch ~/.zshrc

效果

3.3 fasd时空机, 可以跳到任何之前去过的目录, 再也不必cd来cd去了, 可以和更多的命令连用.

fasd可以记录访问目录的权重, 常访问目录权重高, 匹配放在前面.

brew install fasd
# 插件增加fasd
plugins=(git zsh-autosuggestions fasd)
eval "$(fasd --init auto)"
alias j='fasd_cd -d'
source ~/.zshrc

fasd

目录关键词也能识别出来

fasd-folder

alias v='jf -e vim'
alias py3f="jf -e python3"
# 写入.zshrc中
# source ~/.zshrc生效

vim fasd

alias jan='fasd -a'        # any
alias js='fasd -si'       # show / search / select
alias jd='fasd -d'        # directory
alias jf='fasd -f'        # file
alias jsd='fasd -sid'     # interactive directory selection
alias jsf='fasd -sif'     # interactive file selection
alias j='fasd_cd -d'     # cd, same functionality as j in autojump
alias jz='fasd_cd -d -i' # cd with interactive selection
alias jdd='fasd -D' # 删除一个路径

alias v='jf -e vim'
alias nv='jf -e nvim'
alias batf='jf -e bat'
alias catf='jf -e cat'
alias py3f="jf -e python3"
alias lsf="jd -e ls"
alias shf='jf -e sh'
alias commandf='jf -e command'

3.4 zsh-syntax-highlighting高亮显示正确的命令.

zsh-syntax-highlighting官网地址

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
plugins=(git fasd zsh-autosuggestions  zsh-syntax-highlighting)
source ~/.zshrc

zsh-syntax-highlighting

4. Oh My Zsh 主题

主题截图演示地址

# 主题都存放在这个目录下
ls ~/.oh-my-zsh/themes/

# 在.zshrc中, 选择喜欢的主题就行.
ZSH_THEME="robbyrussell"

# 重新生效, 就能看到效果了
source ~/.zshrc