ちゃなべの備忘録

ほぼ備忘録です。

zshをなんかかっこよくしたい【備忘録】

はじめに

こないだ、figという拡張機能(?)をmacのiterm2に入れました。

fig.io

予測補間とかしてくれるからめっちゃ便利なんですこれ。 だけど、gitのローカルレポジトリとかに入った時にbranch名とかをdefaultで出しれくれなくて。 figを調べまくってここら辺の環境を全て整えるのもアリかと思ったのですが、 数年前に話題になったfishを使ってみようかなと思いました。

fish shell

なんでも、いろいろみやすくなるらしい。 だけどちょっと不安で、

  • いままでの設定ファイルが読み込んでくれなそう(.zshrcや.zsh_profileとか)
  • 今後新しいmacbookにした時に設定を作り直すのがめんどくさそう。

やらやら。 なので、ここ周りの不安が解消しそうか調べてみようという感じです。 そしてもし大丈夫そうならinstallもしちゃいたいと思います。

調査

nishinatoshiharu.com

slacknotebook.com

...あれ、これoh-my-zshでよくね? fishにしたときの諸々の設定がめんどくさいと感じていたので悩んでいたのですが、もしzshでいい感じになるならそれがベスト。

ということで、oh-my-zshを入れてみようと思います。 そしてテーマはpowerlineが良さそう。

実装

これを参考にしました

qiita.com

zenn.dev

oh-my-zshの導入

CLIでのdownload

なんかみんな、わざわざ、brew install で zshを入れて、/bin/zshではなく/usr/local/bin/zshに入れてください、って言ってるんだけどなんでなんだろう。 ぼくはdefaultがいいので、brewでわざわざいれずにやってみる。

~ % sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
The $ZSH folder already exists (/Users/ayumu-1212/.local/share/fig/plugins/ohmyzsh).

You ran the installer with the $ZSH setting or the $ZSH variable is
exported. You have 3 options:

1. Unset the ZSH variable when calling the installer:
   `ZSH= sh install.sh`
2. Install Oh My Zsh to a directory that doesn't exist yet:
   `ZSH=path/to/new/ohmyzsh/folder sh install.sh`
3. (Caution) If the folder doesn't contain important information,
   you can just remove it with `rm -r /Users/ayumu-1212/.local/share/fig/plugins/ohmyzsh`

へ?もしかしてfigが入れちゃってる....?

fig

入ってんのかい!! じゃあわざわざinstallする必要ないやんけ。てかfig有能かよ()。

fig上でのPowerlineの設定

ここで、oh-my-zshの設定をしていきましょ。 themaをpowerlineにしたいので、他のpluginをいれてみる。

itermを再起動してみたら!

文字化けーーー。 調べみてみたら、どうやら専用のfontをいれないといけないっぽい。入れてくれよ、、fig、、。

oh-my-zshのテーマ設定でつまづいたこと - Qiita

Powerline用のfontのinstall

powerline用のfontを以下の手順でいれる

~ % git clone https://github.com/powerline/fonts.git --depth=1
Cloning into 'fonts'...
remote: Enumerating objects: 310, done.
remote: Counting objects: 100% (310/310), done.
remote: Compressing objects: 100% (236/236), done.
remote: Total 310 (delta 75), reused 260 (delta 71), pack-reused 0
Receiving objects: 100% (310/310), 10.40 MiB | 4.54 MiB/s, done.
Resolving deltas: 100% (75/75), done.
~ % cd fonts
~/fonts % ./install.sh
Copying fonts...
Powerline fonts installed to /Users/ayumu-1212/Library/Fonts
~/fonts % cd .. 
~/fonts % rm -rf fonts

そして、itermでfontを選ぶ。 ぼくが選んだのはLiberation Mono for Powerline、理由はない。

あと一応VScodeでもfontを選んどく。 ぼくが選んだのはSource Code Pro for Powerline、理由はない。

そしたら、、

素敵!!!

fig上でのpowerlineの詳細設定

だけど、以下を修正したい。

  • 右側に表示されている時刻が要らん
  • homeのpathはチルダ(~)にしてほしい
  • 階層構造全部表示しなくていい(/Documents/develop → /D/d みたいな)

できるところまでやってみよう! まず、時刻。 どうやらRight Promptという名前の設定らしいんだが、figにぽいのがあったので修正。

次はhomeのpathをチルダ表示してほしい、とのことだが、、。 ここまでやって気づく。figだるい。

figは自動補間が良いので使っているが、oh-my-zshもfigにする必要ないよな?(天啓)

ということで、figからoh-my-zshを除いていこう。 といっても、ほとんど簡単で、pluginを消すだけだった。

CLI でのoh-my-zshのinstall

oh-my-zshのダウンロード

itermが元に戻ったことを確認して、じゃあコマンドで入れていこう!

~ % sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Cloning Oh My Zsh...
remote: Enumerating objects: 1295, done.
remote: Counting objects: 100% (1295/1295), done.
remote: Compressing objects: 100% (1250/1250), done.
remote: Total 1295 (delta 25), reused 1184 (delta 25), pack-reused 0
Receiving objects: 100% (1295/1295), 1.07 MiB | 759.00 KiB/s, done.
Resolving deltas: 100% (25/25), done.
From https://github.com/ohmyzsh/ohmyzsh
 * [new branch]      master     -> origin/master
branch 'master' set up to track 'origin/master'.
Switched to a new branch 'master'
/Users/ayumu-1212

Looking for an existing zsh config...
Found ~/.zshrc. Backing up to /Users/ayumu-1212/.zshrc.pre-oh-my-zsh
Using the Oh My Zsh template file and adding it to ~/.zshrc.

         __                                     __
  ____  / /_     ____ ___  __  __   ____  _____/ /_
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
                        /____/                       ....is now installed!


Before you scream Oh My Zsh! look over the `.zshrc` file to select plugins, themes, and options.

• Follow us on Twitter: @ohmyzsh
• Join our Discord community: Discord server
• Get stickers, t-shirts, coffee mugs and more: Planet Argon Shop

んにゃ簡単。

CLI でのPowerlineのinstall

次はpowerlineをいれましょ。

oh-my-zshでpowerlineを堪能する - Qiita

➜  ~ git clone git@github.com:jeremyFreeAgent/oh-my-zsh-powerline-theme.git
Cloning into 'oh-my-zsh-powerline-theme'...
remote: Enumerating objects: 232, done.
remote: Total 232 (delta 0), reused 0 (delta 0), pack-reused 232
Receiving objects: 100% (232/232), 175.76 KiB | 353.00 KiB/s, done.
Resolving deltas: 100% (89/89), done.
➜  ~ cd oh-my-zsh-powerline-theme/
➜  oh-my-zsh-powerline-theme git:(master) ./install_in_omz.sh
Creating symlink from here to your oh-my-zsh themes path...

Done ! (the symlink is ~/.oh-my-zsh/custom/themes/powerline.zsh-theme)

----------------------------------------------------------------------------------

Options:
All options must be overridden in your .zshrc file.
See README.md for more info.

----------------------------------------------------------------------------------

Requirements:
Vim Powerline patched font: See Powerline for vim for more info.
Z shell (zsh): See oh-my-zsh for more info.
Make sure terminal is using 256-colors mode with export TERM="xterm-256color".

テーマをダウンロードできたので、設定。

--ZSH_THEME="robbyrussell"
++ZSH_THEME="powerline"

これで、でけた!

CLI上でのPowerlineの詳細設定

あと調整。

  • ホスト名とユーザー名を非表示に
  • homeのパスはチルダ
  • gitの環境に入ってからブランチ名を表示するハイライトを表示するように。
  • 右の時刻は非表示

.zshrcの追記

# Powerline
POWERLINE_DISABLE_RPROMPT="none" # 右側の表示を非表示
POWERLINE_HIDE_USER_NAME="true" # ユーザー名を非表示
POWERLINE_SHORT_HOST_NAME="true" # ホスト名を短く表示
POWERLINE_PATH="short" # homeのパスをチルダに。

これでやってみた。そしたらこんな感じ。

あのですね。。branch名を表示するところが、レポジトリ下にいない時でも表示されるのが、めちゃめちゃ気に食わん!!! これね。

ということで、これもやめる!!!いろいろ方針変えてすまん!!

Powerlevel10Kの導入

Powerlevel10Kというのを導入することにします。

github.com

テーマのダウンロード

これを入力して、~/.oh-my-zsh/custom/themes/ 内に Powerlevel10k テーマをクローン。

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

テーマの設定変更
--ZSH_THEME="powerline"
++ZSH_THEME="powerlevel10k/powerlevel10k"
起動!

設定もできたので、terminalを再起動します。 すると!!

fontをダウンロードするか聞かれた!!すげぇ!もちろんY。 すると、itermの再起動を要求されるので、再起動。 すると、fontが映っているか確認が入った!手厚い!

諸々の設定の応答に答えていった!

全部設定を終えたら、、、

う、美しぃ。。テーマに全く文句がねぇ...! 最後に、powerlineのテーマを消しておこう。

終わり!最高でした!