zplug で zsh 環境を管理する

imatomix
2020年4月28日 22:48
image

永く zsh を愛用している割に、環境設定は割とすぐに忘れがちです。
最近 MBP を新調したときに zsh のプラグインマネージャを oh-my-zsh から zplug に変更しました。それももう忘れつつあるので、思い出しながらメモっておきます。

zsh のインストール

mac の場合

mac の場合は、macOS Catalina から zsh がデフォルトになったらしいので、インストールは不要。 Catalina以前は、

コマンドラインツールのインストール
$ xcode-select --install
Homebrew で zsh のインストール
$ brew install zsh

windowsの場合

wsl2 でlinux環境(ここでは ubuntu)を用意した後、下記の通りubuntuにzshをインストールする

ubuntu の場合

以下のコマンドでインストール
$ sudo apt-get install zsh

シェルの変更

chsh コマンドで変更する。$(which zsh) はzshへのパス。
$ chsh -s $(which zsh)

zplug のインストール

以下のコマンドでインストール

.zshrc の設定

自分好み設定を.zshrc に記述する。以下は僕の設定。ほぼデフォルト設定で#zplug以降が追加したzplugの設定
~/.zshrc
# Set up the prompt autoload -Uz promptinit promptinit setopt histignorealldups sharehistory # キーバインドをviライクにする bindkey -v # ヒストリー機能 HISTSIZE=1000 SAVEHIST=1000 HISTFILE=~/.zsh_history # Use modern completion system autoload -Uz compinit compinit zstyle ':completion:*' auto-description 'specify: %d' zstyle ':completion:*' completer _expand _complete _correct _approximate zstyle ':completion:*' format 'Completing %d' zstyle ':completion:*' group-name '' zstyle ':completion:*' menu select=2 eval "$(dircolors -b)" zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} zstyle ':completion:*' list-colors '' zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*' zstyle ':completion:*' menu select=long zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s zstyle ':completion:*' use-compctl false zstyle ':completion:*' verbose true zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' # zplug source ~/.zplug/init.zsh ## 非同期処理 zplug "mafredri/zsh-async" ## テーマ zplug "themes/wedisagree", from:oh-my-zsh, as:theme ## シンタックスハイライト zplug "zsh-users/zsh-syntax-highlighting" zplug "chrissicool/zsh-256color" ## 入力アシスト zplug "zsh-users/zsh-history-substring-search" zplug "zsh-users/zsh-autosuggestions" zplug "zsh-users/zsh-completions" zplug "mrowa44/emojify", as:command ## 未インストールのプラグインをインストール if ! zplug check --verbose; then printf 'Install? [y/N]: ' if read -q; then echo; zplug install fi fi # コマンドにパスを通し、プラグインを読み込む zplug load --verbose
source コマンドで .zshrc を反映させる
$ source .zshrc
未インストールのプラグインがある場合、インストールするかどうか聞かれるので、y を押してインストールする

ゴール

こんな感じになりました。

image