Macのログインシェルをzsh+Preztoに変更した

どうでもいい話ですが、昔はtcshを常用していましたが今はzshを使ってます。
でも最近はデフォルトのbashのままのサーバもあったりして自分も丸くなったなーと思うけど、新しく買ったMacbook Air使ってて流石に不便なので頑張りました。

zshに変更

Homebrewでzshをインストールしてデフォルトのログインシェルを変更

$ brew install zsh
$ sudo vi /etc/chsh
/usr/local/bin/zsh ←追加

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

Prezto導入

インストール

git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
$ setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
  ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
ln: /Users/gozu/.zshrc: File exists

.zshrcがすでに存在するとだめみたい

$ mv .zshrc .zshrc.org

$ setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
  ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
ln: /Users/gozu/.zlogin: File exists
ln: /Users/gozu/.zlogout: File exists
ln: /Users/gozu/.zpreztorc: File exists
ln: /Users/gozu/.zprofile: File exists
ln: /Users/gozu/.zshenv: File exists

lrwxr-xr-x   1 gozu  staff      35 11  4 17:24 .zlogin -> /Users/gozu/.zprezto/runcoms/zlogin
lrwxr-xr-x   1 gozu  staff      36 11  4 17:24 .zlogout -> /Users/gozu/.zprezto/runcoms/zlogout
lrwxr-xr-x   1 gozu  staff      38 11  4 17:24 .zpreztorc -> /Users/gozu/.zprezto/runcoms/zpreztorc
lrwxr-xr-x   1 gozu  staff      37 11  4 17:24 .zprofile -> /Users/gozu/.zprezto/runcoms/zprofile
lrwxr-xr-x   1 gozu  staff      35 11  4 17:24 .zshenv -> /Users/gozu/.zprezto/runcoms/zshenv
lrwxr-xr-x   1 gozu  staff      34 11  4 17:26 .zshrc -> /Users/gozu/.zprezto/runcoms/zshrc

中途半端に処理が行われていたようなので消してもう一度

$ rm .zlogin.org
$ rm .zlogout.org
$ rm .zpreztorc
$ rm .zprofile
$ rm .zshenv
$ rm .zshrc

$ setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
  ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done

OK!
新しいセッションを開けばPrestoで起動します。

設定

デフォルトのテーマが見ずらいのでテーマを変えます。

  • 一覧
$ prompt -l
Currently available prompt themes:
agnoster cloud damoekri giddie kylewest minimal nicoulaj paradox peepcode powerlevel10k powerlevel9k powerline pure skwp smiley sorin steeef adam1 adam2 bart bigfade clint default elite2 elite fade fire off oliver pws redhat restore suse walters zefram
  • プレビュー
$ prompt -p
(全部出るけど所々文字化け)

PowerLine対応フォントが入ってないのでRictyの対応版をインストールします。
ここはいつも使っている本家のRicty入れておきます。(Diminishedの方が楽だけど使い慣れてるので)

www.konosumi.net

$ brew tap sanemat/font
$ brew install ricty
(snip)
==> ricty
***************************************************
Generated files:
  /usr/local/opt/ricty/share/fonts/RictyDiscord-Regular.ttf
      /usr/local/opt/ricty/share/fonts/Ricty-Oblique.ttf
      /usr/local/opt/ricty/share/fonts/Ricty-Bold.ttf
      /usr/local/opt/ricty/share/fonts/RictyDiscord-Oblique.ttf
      /usr/local/opt/ricty/share/fonts/Ricty-Regular.ttf
      /usr/local/opt/ricty/share/fonts/Ricty-BoldOblique.ttf
      /usr/local/opt/ricty/share/fonts/RictyDiscord-Bold.ttf
      /usr/local/opt/ricty/share/fonts/RictyDiscord-BoldOblique.ttf
***************************************************
To install Ricty:
  $ cp -f /usr/local/opt/ricty/share/fonts/Ricty*.ttf ~/Library/Fonts/
  $ fc-cache -vf
***************************************************

$ brew options ricty
--with-patch-in-place
    Patch Powerline glyphs directly into Ricty fonts without creating new 'for Powerline' fonts
--with-powerline
    Patch for Powerline
--without-fullwidth
    Disable fullwidth ambiguous characters
--without-visible-space
    Disable visible zenkaku space
(使えるオプションを表示)

$ brew reinstall --with-powerline --with-patch-in-place ricty
==> Reinstalling sanemat/font/ricty --with-powerline --with-patch-in-place
==> Downloading http://yusa.lab.uec.ac.jp/~yusa/ricty/ricty_generator-4.1.1.sh
Already downloaded: /Users/gozu/Library/Caches/Homebrew/downloads/aacf520745eb723ecce41723f843ab10ead03a7323099ce2b7c51123d0c01e77--ricty_generator-4.1.1.sh
==> Downloading https://osdn.jp/frs/redir.php?m=gigenet&f=%2Fmix-mplus-ipa%2F63545%2Fmigu-1m-20150712.zip
Already downloaded: /Users/gozu/Library/Caches/Homebrew/downloads/4e24ddf8bf40fc096f34c12ec91e4469efcded452334dcbefb265ca0343ba455--migu-1m-20150712.zip
==> Downloading https://github.com/google/fonts/raw/f0e90b27b6e567af9378952a37bc8cf29e2d88e9/ofl/inconsolata/Inconsolata-
Already downloaded: /Users/gozu/Library/Caches/Homebrew/downloads/24a8808bea96ca8579bc893547b86241448b2944cca2414aca6d6400986529a3--Inconsolata-Regular.ttf
==> Downloading https://github.com/google/fonts/raw/f0e90b27b6e567af9378952a37bc8cf29e2d88e9/ofl/inconsolata/Inconsolata-
Already downloaded: /Users/gozu/Library/Caches/Homebrew/downloads/0f8e8be9545eb996c487dc08e9d95b408e9b5d0084889938d588d7bf7c98c31f--Inconsolata-Bold.ttf
==> Downloading https://github.com/powerline/fontpatcher/archive/c3488091611757cb02014ed7ed2f11be0208da83.zip
==> Downloading from https://codeload.github.com/powerline/fontpatcher/zip/c3488091611757cb02014ed7ed2f11be0208da83
######################################################################## 100.0%
==> Patching
patching file scripts/powerline-fontpatcher
==> sh ./ricty_generator-4.1.1.sh Inconsolata-Regular.ttf Inconsolata-Bold.ttf migu-1m-regular.ttf migu-1m-bold.ttf
==> fontforge -lang=py -script /private/tmp/ricty-20191104-6196-hotccb/scripts/powerline-fontpatcher --no-rename RictyDis
==> fontforge -lang=py -script /private/tmp/ricty-20191104-6196-hotccb/scripts/powerline-fontpatcher --no-rename Ricty-Ob
==> fontforge -lang=py -script /private/tmp/ricty-20191104-6196-hotccb/scripts/powerline-fontpatcher --no-rename Ricty-Bo
==> fontforge -lang=py -script /private/tmp/ricty-20191104-6196-hotccb/scripts/powerline-fontpatcher --no-rename RictyDis
==> fontforge -lang=py -script /private/tmp/ricty-20191104-6196-hotccb/scripts/powerline-fontpatcher --no-rename Ricty-Re
==> fontforge -lang=py -script /private/tmp/ricty-20191104-6196-hotccb/scripts/powerline-fontpatcher --no-rename Ricty-Bo
==> fontforge -lang=py -script /private/tmp/ricty-20191104-6196-hotccb/scripts/powerline-fontpatcher --no-rename RictyDis
==> fontforge -lang=py -script /private/tmp/ricty-20191104-6196-hotccb/scripts/powerline-fontpatcher --no-rename RictyDis
==> Caveats
***************************************************
Generated files:
  /usr/local/opt/ricty/share/fonts/RictyDiscord-Regular.ttf
      /usr/local/opt/ricty/share/fonts/Ricty-Oblique.ttf
      /usr/local/opt/ricty/share/fonts/Ricty-Bold.ttf
      /usr/local/opt/ricty/share/fonts/RictyDiscord-Oblique.ttf
      /usr/local/opt/ricty/share/fonts/Ricty-Regular.ttf
      /usr/local/opt/ricty/share/fonts/Ricty-BoldOblique.ttf
      /usr/local/opt/ricty/share/fonts/RictyDiscord-Bold.ttf
      /usr/local/opt/ricty/share/fonts/RictyDiscord-BoldOblique.ttf
***************************************************
To install Ricty:
  $ cp -f /usr/local/opt/ricty/share/fonts/Ricty*.ttf ~/Library/Fonts/
  $ fc-cache -vf
***************************************************
==> Summary
🍺  /usr/local/Cellar/ricty/4.1.1: 12 files, 27MB, built in 3 minutes 15 seconds
(PowerLine対応パッチを当てて再インストール。"--with-patch-in-place ricty"は新しいフォントを作らず元のファイルにパッチを当てるということらしい)

$ cp -f /usr/local/opt/ricty/share/fonts/Ricty*.ttf ~/Library/Fonts/
$ fc-cache -vf

iTerm2のフォントにRictyを指定

$ prompt -p
(ちゃんと出たー(≧∇≦)b)

※ 後で気がついたけど、今どきのiTerm2は、 Preferences > Profiles > Text > []Use built-in Powerline glyphs でPowerLine表示できるのね。ゴニョゴニョする必要なかったのか・・・。

  • iTerm2との調整

Preztoのテーマはagnosterで良さそうなのだが、iTerm2の透過を有効にしていると字が暗くて見ずらい。
なのでiTerm2のテーマを変えてみる。
Preferences > Profiles > Colors > Color Presets... から「Pastel(Dark Background)」にする。結構良くなったけど透過率が高めなら見やすいかなという感じ。
透過率低めなら、Visit Online GalleryからHybridを選ぶと良さそう。
※ 透過設定(Preferences > Profiles > Window > Transeparency)をいじったら下にある Keep background colors opaqueにチェックを入れる。PowerLineの三角が綺麗に塗られるようになります。

iterm2colorschemes.com

とりあえず、iTerm2の透過率(Transparency)は10%程度にしてテーマをHybrid、Preztoのテーマをagnosterでやってみることにした。

$ prompt agnoster
(agnosterを試してみる)

$ vi ~/.zpreztorc
#zstyle ':prezto:module:prompt' theme 'sorin'
zstyle ':prezto:module:prompt' theme 'agnoster'

$ source ~/.zpreztorc

ということでこんな感じになりました。

f:id:gozuk16:20191104193012p:plain