LoginSignup
16
18

More than 5 years have passed since last update.

zplugで管理するzsh環境

Last updated at Posted at 2018-05-15

はじめに

エンジニアたるもの、シェルを使いやすくしてなんぼだと思います。
数年zshを使いプラグインマネージャーをoh-my-zshを使ってきました。

しかし、もっさりしているのと気分転換に今回zplugに乗り換えました。
とても使いやすく、設定もわかりやすかったので、シェルに抵抗のある方もぜひ試してみてください。

環境

  • Mac OS X 10.13.4

oh-my-zshのアンインストール

$ uninstall_oh_my_zsh

必要な方だけアンインストールしてください

導入

brewでインストールを行うのが楽です。

$ brew install zplug

インストールが終わったら、which zplugでパスを確認しておきましょう。

自分の場合、/usr/local/opt/zplugというパスになっていました。

.zshrcに設定を記入

vi ~/.zshrcで設定ファイルを開きます。

プロンプトにpureを使っているので、.zshrcを書くまえにnpm install --global pure-promptしておいてください

export ZPLUG_HOME=/usr/local/opt/zplug
source $ZPLUG_HOME/init.zsh

autoload -U promptinit; promptinit
# プロンプトを変更
prompt pure

setopt auto_cd

zplug 'zsh-users/zsh-autosuggestions'
zplug 'zsh-users/zsh-completions'
zplug 'zsh-users/zsh-syntax-highlighting'
zplug "mollifier/anyframe"
zplug "mollifier/cd-gitroot"
# zplug "b4b4r07/enhancd", use:enhancd.sh
zplug "zsh-users/zsh-history-substring-search", hook-build:"__zsh_version 4.3"
zplug "junegunn/fzf-bin", as:command, from:gh-r, rename-to:fzf
zplug "junegunn/fzf", as:command, use:bin/fzf-tmux
zplug "supercrabtree/k"
zplug "junegunn/fzf", use:shell/key-bindings.zsh
zplug "junegunn/fzf", use:shell/completion.zsh
zplug "b4b4r07/enhancd", use:init.sh
zplug "paulirish/git-open", as:plugin
zplug "zsh-users/zsh-syntax-highlighting", defer:2
: "cd先のディレクトリのファイル一覧を表示する" && {
  [ -z "$ENHANCD_ROOT" ] && function chpwd { tree -L 1 } # enhancdがない場合
  [ -z "$ENHANCD_ROOT" ] || export ENHANCD_HOOK_AFTER_CD="tree -L 1" # enhancdがあるときはそのHook機構を使う
}

: "sshコマンド補完を~/.ssh/configから行う" && {
  function _ssh { compadd $(fgrep 'Host ' ~/.ssh/*/config | grep -v '*' |  awk '{print $2}' | sort) }
}

# 未インストール項目をインストールする
if ! zplug check --verbose; then
    printf "Install? [y/N]: "
    if read -q; then
        echo; zplug install
    fi
fi

# コマンドをリンクして、PATH に追加し、プラグインは読み込む
zplug load --verbose

上記で編集終わったら、source ~/.zshrcを実行するとプラグインのインストールが始まります。

便利なプラグインがこちらより確認出来るので、みて見てください。

以上です。

補足

chpwd: command not found: tree

以上のようなエラーが出た方は、以下のコマンドを実行することで解決出来ます。

$ brew install tree

参考

16
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
18