LoginSignup
1

More than 3 years have passed since last update.

Macにzshをインストール

Last updated at Posted at 2020-07-29

2020年3月25日深夜以降?にqiita問題があった為、
2019年頃の本記事を3月29日にqiitaから削除し他サイト移行を検討した。

その後、問題なくなったのでテストとして本記事のみ戻してみる。

MacOS 10.9
zsh 5.7.1 -> 5.8 2020年3月上旬 更新

MacOSが公式にzshを採用したのでzshを入れる。

1.注意点

bash同様zshは重要な基本ソフトである。
安易にbrew install zshを推奨しているサイトが多い。
homebrewトラブル時に対処できない場合を避けるため
homebrewでなく手動でzshをインストール。

2.ダウンロード

公式
公式ページの右のダウンロードの下のソースから手動でダウンロード。
ZSH - THE Z SHELL

ダウンロードのリンク。
ZSH - Source download (http://zsh.sourceforge.net/Arc/source.html)

コマンドでダウンロードする場合。

$ curl -LO https://sourceforge.net/projects/zsh/files/zsh/5.8/zsh-5.8.tar.xz

3.ビルド

$ tar Jxvf zsh-5.8.tar.xz
$ cd zsh-5.8
$ ./configure --enable-multibyte
$ make
($ make check 実行してもしなくても良い。MBairで二分くらい)
$ sudo make install

/bin/zshは消さないこと。

4.zsh-completionsインストール省略。

zsh-completionsは非標準コマンドを補完できるようになる素敵なプラグインだが、zshはbashの代替なのでしばらくインストールしない。

公式
GitHub - zsh-users/zsh-completions: Additional completion definitions for Zsh.
https://github.com/zsh-users/zsh-completions

brewのzsh-completionsを使ってzshの補完を強化する - Qiita

5.bash の設定を引き継ぐ

重要
zshの設定ファイルの読み込み順序と使い方Tipsまとめ - Qiita

上の URLには、読み込み順として次のようになる。
global) /etc/zshenv
local ) ~/.zshenv
global) /etc/zprofile
local ) ~/.zprofile
global) /etc/zshrc
local ) ~/.zshrc
global) /etc/zlogin
local ) ~/.zlogin

よって、bash_profileの出力先はzprofileでなく.zshenvとする。

cat .bash_profile >> .zshenv

cat .bashrc >> .zshrc

6..zshrc .bashrcで異なる点はプロンプトとhistoryと補完機能だけで後は互換。

# --------
# ZSH
# --------
# 補完機能
autoload -Uz compinit
compinit
zstyle ':completion:*' menu select

# --------
# ZSH history
# --------
alias hi='history -30'
# 履歴ファイルの保存先
export HISTFILE=${HOME}/.zsh_history
# メモリに保存される履歴の件数
export HISTSIZE=10000
# 履歴ファイルに保存される履歴の件数
export SAVEHIST=100000
# 重複を記録しない
setopt hist_ignore_dups
# 開始と終了を記録
setopt EXTENDED_HISTORY
# --------
# ZSH prompt
# --------
# promptinitを使う場合はこちらを読み込む
# 利用可能なpromptの設定を見る
# $ prompt -l
# promptを設定する
# $ prompt [prompt名]
# promptを独自で変更
# PROMPT='%m:%F{green}%c%f %n%# '
PROMPT='%F{yellow}%c%f $ '

プロンプト
とりあえずZshを使えば良いんだろう? - Qiita

7.Macでログインシェルを確認/変更

$ sudo vim /etc/shells
/usr/local/bin/zsh を追加する

$ chsh -s /usr/local/bin/zsh

ログインシェルにzshを使ってない場合は
source ~/.zshenv
source ~/.zshrc

ログインシェルにzshを使っている場合は、ログアウト。(又は再起動)

Macでログインシェルを確認/変更するいくつかの方法

以上

--

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
1