備忘録

開発の日々の備忘録

macでzsh使う


あけおめです。

macのログインシェルをzshに変えた際のメモ。

zshインストール


Homebrew入れてなければここから。

Homebrew — OS X 用パッケージマネージャー

補完機能を強化してくれるzsh-completionsも一緒に入れとく。

$ brew install --without-etcdir zsh
$ brew install zsh-completions

シェル変更


インストールしたzshをログインシェルに登録するための下準備。

$ sudo sh -c "echo '/usr/local/bin/zsh' >> /etc/shells"

使えるシェルを確認。

$ cat /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 ←さっき追加したzsh

シェルを変更する

$ chpass -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 ---

ターミナル再起動後になんかつらつらと出る。
(0)を選べば空の.zshrcが作成されるので(0)選ぶ (zshの設定は/.zshrcに記述してく)

まずはzshと一緒に入れたzsh-completionsを有効にする。

% echo 'fpath=(/usr/local/share/zsh-completions $fpath)' >> ~/.zshrc

設定反映。

% source ~/.zshrc

とりあえずここまで。

最後に


zshはカスタマイズしてこそなので色々調べて自分好みのzshrcを作ってく!