Macでシェルをbashからzshに変更し、Zgenを導入した手順
zshの最新版をインストールをし、zshのプラグインマネージャーである「zgen」を導入した手順をまとめています。
zshのインストール
# 現在のzshのバージョン確認
$ /bin/zsh --version
zsh 5.2 (x86_64-apple-darwin16.0)
# 最新バージョンの確認
$ brew info zsh
zsh: stable 5.7.1 (bottled), HEAD
(略)
最新版をインストールしてきます。
$ brew install zsh
ちゃんと最新版がインストールできたか確認します。
$ /usr/local/bin/zsh --version
zsh 5.7.1 (x86_64-apple-darwin16.7.0)
最新の5.7.1インストールできているみたいです。
ログインシェルの変更
/etc/shellsにzshのパスを追加します。
$ sudo vi /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
/usr/local/bin/zsh <-- これを追加しました。
ログインシェルを変更するchshコマンドを使ってログインシェルを変更します。
$ chsh -s /usr/local/bin/zsh
(パスワードを尋ねられる)
ターミナルを再起動してみます。
This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~). This function can help you with a few settings that should
make your use of the shell easier.
You can:
(q) Quit and do nothing. The function will be run again next time.
(0) Exit, creating the file ~/.zshrc containing just a comment.
That will prevent this function being run again.
(1) Continue to the main menu.
--- Type one of the keys in parentheses ---
このようなメッセージが表示されました。zshの設定ファイル(.zprofile, .zshrcなど)が~ディレクトリにないから表示されているそうです。
とりあえずqで抜けましょう。
そして、今まで利用していた~/.bash_profileを~/.zshrcにコピーします。
% cat ~/.bash_profile >> ~/.zshrc
そして再起動すれば、エラーは消えます。
Zgenの導入
Zgenは軽量でシンプルなZshプラグインマネージャーです。メモがてらにまとめていきます。
まずは、githubからコピーしてきます。
% git clone https://github.com/tarjoilija/zgen.git "${HOME}/.zgen"
.zshrcに以下を追記します。
% vi ~/.zshrc
# load zgen
source "${HOME}/.zgen/zgen.zsh"
# if the init scipt doesn't exist
if ! zgen saved; then
# specify plugins here
# 以下に追加したいプラグイン記入
zgen oh-my-zsh
zgen load ・・・
・
・
# generate the init script from plugins above
zgen save
fi
初期化スクリプトをリセットしてから変更を反映させる。
% zgen reset
% source ~/.zshrc
以上でシェルをzshに変更し、zgenを導入できました。
自分の環境に合わせた変更
.zshrcに色々書いていたので.zshrc.zgenを新規作成しました。
以下のコマンドで.zshrc.zgenを読み込むようにします。
.zshrc
[[ -f $HOME/.zshrc.zgen ]] && source $HOME/.zshrc.zgen
以下が.zshrc.zgenの内容となっています。
.zshrc.zgen
if [[ -f "$HOME/.zgen/zgen.zsh" ]]; then
# load zgen
source "$HOME/.zgen/zgen.zsh"
# if the init scipt doesn't exist
if ! zgen saved; then
# specify plugins here
zgen oh-my-zsh
zgen oh-my-zsh themes/clean
zgen load zsh-users/zsh-completions
zgen load zsh-users/zsh-history-substring-search
zgen load zsh-users/zsh-syntax-highlighting
# generate the init script from plugins above
zgen save
fi
fi