文科生 / 网管 / 看书写字 / 动漫 / 不爱国

zplug 武装 zsh

2018.05.10

很多人用 oh-my-zsh ,但并不是只有一种选择。

awesome-zsh-plugins 这个项目里列了超级多的 " zsh 配置框架 "。 zplug 是从 fzfvim-plug 这两个项目的作者 junegunn 那边爬到的,zplugvim-plug 风格类似,而作者的另一个项目 enhancd 也是神器,他的 blog 质量也很高,值得关注(日语?用翻译的!


markdown 里贴链接还是有点费力…唠叨半天,开始用吧——

疾速体验

# 不想看解释,直接执行这个 shell 然后重新打开终端即可
wget https://guojing.io/attach/zplug.sh | bash 

安装

apt install zplug fzf        # debian

# 如果发行版源里没有——
export ZPLUG_HOME=~/.zplug
git clone https://github.com/zplug/zplug $ZPLUG_HOME

编辑配置文件

vim ~/.zshrc

# Check if zplug is installed
# if [[ $(grep -w ID /etc/os-release) == "ID=debian" ]]; then
#     source /usr/share/zplug/init.zsh
# fi
# 以上几行简单适配了 apt 安装的 zplug

source ~/.zplug/init.zsh

# Misc
export EDITOR=vim
export GIT_EDITOR="${EDITOR}"
export PATH=$ZPLUG_HOME/bin:$PATH
export PAGER="most"
export LANG="en_US.UTF-8"

# History config
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=$ZPLUG_HOME/zsh_history
setopt append_history
setopt share_history
setopt long_list_jobs
setopt hist_expire_dups_first
setopt hist_ignore_dups
setopt hist_ignore_all_dups
setopt hist_ignore_space
setopt hist_find_no_dups
setopt hist_reduce_blanks
setopt hist_verify
setopt hist_no_store
setopt interactivecomments
zstyle ':completion:*' rehash true

# Key binds
bindkey '\eOA'    history-substring-search-up
bindkey '\eOB'    history-substring-search-down
bindkey "\e[1;5D" backward-word
bindkey "\e[1;5C" forward-word
bindkey  "^[[H"   beginning-of-line
bindkey  "^[[F"   end-of-line

# Zplug plugins
zplug "zsh-users/zsh-completions"
zplug "zsh-users/zsh-history-substring-search"
zplug "zsh-users/zsh-syntax-highlighting"
zplug "zsh-users/zsh-autosuggestions"
zplug "rimraf/k"
zplug "b4b4r07/enhancd", use:init.sh
zplug "b4b4r07/emoji-cli"
zplug "mrowa44/emojify", as:command
zplug "k4rthik/git-cal", as:command
zplug "lib/completion", from:oh-my-zsh
zplug "plugins/colored-man-pages", from:oh-my-zsh
zplug "plugins/man", from:oh-my-zsh
zplug "plugins/sudo", from:oh-my-zsh
zplug "plugins/encode64", from:oh-my-zsh
zplug 'plugins/extract', from:oh-my-zsh
zplug "themes/half-life", from:oh-my-zsh, as:theme

zplug "junegunn/fzf"
zplug "junegunn/fzf-bin", \
    from:gh-r, \
    as:command, \
    rename-to:fzf, \
    use:"*linux*amd64*"
source $ZPLUG_HOME/repos/junegunn/fzf/shell/completion.zsh
source $ZPLUG_HOME/repos/junegunn/fzf/shell/key-bindings.zsh

# debian 使用 apt install fzf 适配以下几行,删除上面配置 fzf 的部分即可
# if [[ -e /usr/share/doc/fzf/examples/key-bindings.zsh ]]; then
#   source /usr/share/doc/fzf/examples/key-bindings.zsh
# fi

if zplug check b4b4r07/enhancd; then
    export ENHANCD_FILTER=fzf-tmux
fi

# Install packages that have not been installed yet
if ! zplug check --verbose; then
    printf "Install? [y/N]: "
    if read -q; then
        echo; zplug install
    else
        echo
    fi
fi
zplug load

然后 source ~/.zshrc 开始体验吧

有哪些点不错?

  • ctrl + r 唤起 fzf 作为搜索后端的历史记录选单,支持模糊匹配
  • cd 直接回车,可超快速的进入曾经访问过的文件夹
  • x ~/压缩包/路径/xxx.tar 解压文件,支持所有格式
  • k 比 ls 、ll 更快的列出文件夹下内容
  • 输入命令前缀上下键可快速定位 " 相关历史 '',比如输入 ssh 上下键会翻出所有登陆过的主机
  • 可以通过 zplug 指令自动下载 github 上任意 release 文件到本地
  • 酷!大部分人都用 oh-my-zsh 的时候,我们完全定制了自己的配置 ~