关系
先说下这几样东西的关系:
zsh是一个类似bash的终端。 https://www.zsh.org
ohmyzsh是一个管理zsh配置文件的东西(框架),自带一些主题插件云云。https://github.com/robbyrussell/oh-my-zsh
autojump是一个快速cd工具,可以自动记录你经常cd的目录,实现简短指令就能到达。并不是一定依赖zsh。https://github.com/wting/autojump
fzf是一个文件搜索工具,类似Windows下的everything,同样并不是一定依赖zsh。https://github.com/junegunn/fzf
zsh-git-prompt是一个能够展示更好的git信息的工具,看名字就知道必须zsh。https://github.com/olivierverdier/zsh-git-prompt
zsh的安装
yum install -y zsh #安装zsh
chsh -s /usr/bin/zsh #启用zsh
oh-my-zsh的安装
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
个人使用的主题,基于clean+fishy,加上zsh-git-prompt。
修改ZSH_THEME=”wbb”
_fishy_collapsed_wd() {
echo $(pwd | perl -pe '
BEGIN {
binmode STDIN, ":encoding(UTF-8)";
binmode STDOUT, ":encoding(UTF-8)";
}; s|^$ENV{HOME}|~|g; s|/([^/.])[^/]*(?=/)|/$1|g; s|/\.([^/])[^/]*(?=/)|/.$1|g
')
}
if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="white"; fi
#PROMPT='%{$fg[$NCOLOR]%}%B%n%b%{$reset_color%}:%{$fg[blue]%}%B%c/%b%{$reset_color%} $(git_prompt_info)%(!.#.$) '
#PROMPT='%{$fg[blue]%}%B%~/%b%{$reset_color%} $(git_prompt_info)%(!.#.$) '
PROMPT='%{$fg[blue]%}%B$(_fishy_collapsed_wd)%b%{$reset_color%} $(git_super_status)%(!.#.$) '
RPROMPT='[%*]'
# LS colors, made with https://geoff.greer.fm/lscolors/
export LSCOLORS="Gxfxcxdxbxegedabagacad"
export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:'
最终效果是可以简短展示路径、可以显示git状态。
简单不卡版: PROMPT='%B%F{red}%m %B%F{blue}%~%f%b $(git_prompt_info)%f%b# '
autojump安装
git clone https://github.com/wting/autojump.git
cd autojump
./install.py
安装完会出提示,把两行内容复制粘贴到.zshrc后source一下就生效。
简单使用方法:
j:进入权重最高的目录(经常去的目录)
j -s:查看目录权重列表
j m: 进入包含”m”字符的权重最高的目录
j m之后按tab:可以自动列出所有含”m”字符的目录供选择。
j -d:当前目录权重-10
j -i:当前目录权重+2
zsh-git-prompt安装
#先在root目录clone项目
git clone https://github.com/olivierverdier/zsh-git-prompt.git
#在.zshrc中添加
source /root/zsh-git-prompt/zshrc.sh
export ZSH_THEME_GIT_PROMPT_CACHE=yes #这行的作用是开启git缓存
这样,前面主题中的git_super_status就有效果了。
fzf安装
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
#fzf会自动添加内容到.zshrc,source一下就生效:
source ~/.zshrc
简单用法介绍
按ctrl+t,会出来一个列表可以选择/搜索目录下任何文件,选中后自动输入,所以可以结合各种指令使用。
按alt+c,会出来一个列表可以选择/搜索目录下的任何目录,不需要结合指令,选中后自动进入目录。
home和end失效的办法
.zshrc中添加:
#Rebind HOME and END to do the decent thing:
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
case $TERM in (xterm*)
bindkey '\eOH' beginning-of-line
bindkey '\eOF' end-of-line
esac
#To discover what keycode is being sent, hit ^v
#and then the key you want to test.
#And DEL too, as well as PGDN and insert:
bindkey '\e[3~' delete-char
bindkey '\e[6~' end-of-history
bindkey '\e[2~' redisplay
#Now bind pgup to paste the last word of the last command,
bindkey '\e[5~' insert-last-word
Centos6下可安装最新版本zsh
yum install http://mirror.ghettoforge.org/distributions/gf/el/6/plus/x86_64/zsh-5.0.7-5.gf.el6.x86_64.rpm