shellをいい感じにする

いろいろ開発環境見直してる流れでshell環境も見直そうと思い立ったのでそのメモ

fish, nushell
最初はzshのプラグインとかRust製のCLIツールとか入れるくらいに考えてたんだけどfishとかnushellといったものが気になってしまったので調べた。
fishに関しては以下の記事とかが参考になった
nushellについて
どっかでterminalの入力で補完効いているのをみていいなと思っていたらfishだとそれができるらしいと知って導入する気になった。また、fisherというパッケージマネージャーでfzfといった有名どころのツールも導入できそうだし、何よりそんなに設定作り込まなくてもすぐに導入できそうなのがいい感じ。
nushellはだいぶshell環境が別物になりそうな気がしたのでやめた。まだ、破壊的変更もありそうな気配がしたのとTerminalのWrapみたいな高機能ツール感を感じた。ghosttyみたいなシンプル、最低限のconfigで高機能みたいなツールのが好み。

やっぱりzsh
1点だけ気になってたのがPOSIX非互換という点で、shell scriptがfishだと動かないとかそういうのあると面倒くさそうだなという点。実際、fishにしたけどzshに戻したみたいな記事を書いている人はけっこういた。
いろいろ記事まさぐっていたらmizshiさんのスクラップ出てきて補完だけ欲しいならzshのままでもできるということを知ったのでzshのままいくことにしました。

figってAmazon Qのことか。いれてたけど全然使ってなかったな。。むしろじゃまくらいに思ってた。ということでterminalでの補完に関してはAmazon Q Developer CLIを使うことに。

Starship
これはfish調べているときに知って、導入も簡単そうだったので入れてみる。
brew install starship
.zshrcに以下を記載する
eval "$(starship init zsh)"
デフォルトでもいいが、少し情報が多い気がするのでconfigファイルを作成する
touch ~/.config/starship.toml
# エディターの補完を設定スキーマに合わせて取得
"$schema" = 'https://starship.rs/config-schema.json'
# シェルのプロンプトの間に空行を挿入する
add_newline = true
# ref https://github.com/starship/starship/discussions/1107?sort=top#discussioncomment-10214050
format = """
[╭{owo} ](bold green)$username$directory$battery$all$line_break$character"""
[character]
success_symbol = '[╰─>](bold green)'
error_symbol = '[x >](bold red)'
[git_branch]
format = '[$symbol$branch(:$remote_branch) ]($style)'
# ref https://zenn.dev/link/comments/ced6da507bf16f
[git_status]
format = '$all_status$ahead_behind '
conflicted = ''
ahead = ''
behind = ''
diverged = ''
up_to_date = '[✓](bold green)'
untracked = ''
stashed = ''
modified = '🔥'
staged = ''
renamed = ''
deleted = ''
[time]
disabled = false
format = '🕙 [$time]($style) '
time_format = '%m/%d %R'
[aws]
disabled = true
[gcloud]
disabled = true
starshipのGitHub repositoryでconfigを紹介してくれてたので適当によさそうなのを参考にした。gitのstatusは考えるのが面倒くさかったのでmizchiさんの設定を参考にした。AWSとGCPはデフォルトだと少し情報が多すぎるたのでdisabledにした。profileあたりは表示されてたほうが嬉しい気もするが今CLIでクラウド操作しないから必要になったらまた考える。
gitのステータスがやっぱり見たくなったので以下のように変えた
# エディターの補完を設定スキーマに合わせて取得
"$schema" = 'https://starship.rs/config-schema.json'
# シェルのプロンプトの間に空行を挿入する
add_newline = true
# ref https://github.com/starship/starship/discussions/1107?sort=top#discussioncomment-10214050
format = """
[╭{owo} ](bold green)$username$directory$battery$all$line_break$character"""
[character]
success_symbol = '[╰─>](bold green)'
error_symbol = '[╰─>](bold green)'
[status]
disabled = false
style = "red"
symbol = " \\(╯°□°)╯︵ ┻━┻ "
format = "\b[$symbol$status](fg:$style)"
[git_branch]
format = '[$symbol$branch(:$remote_branch) ]($style)'
# ref https://github.com/starship/starship/discussions/1107#discussioncomment-345147
[git_status]
style = "#f05133"
format = "($conflicted$staged$modified$renamed$deleted$untracked$stashed$ahead_behind\b )"
conflicted = "[ ](fg:88)[ ${count} ](fg:white bg:88)[ ](fg:88)"
staged = "[M$count ](fg:green)"
modified = "[M${count} ](fg:red)"
renamed = "[R${count} ](fg:208)"
deleted = "[ ${count} ](fg:208)"
untracked = "[?${count} ](fg:red)"
up_to_date = '[✓](bold green)'
stashed = " ${count} "
ahead = "[ ${count} ](fg:purple)"
behind = "[ ${count} ](fg:yellow)"
diverged = "[](fg:88)[ נּ ](fg:white bg:88)[ ${ahead_count} ](fg:purple bg:88)[ ${behind_count} ](fg:yellow bg:88)[ ](fg:88)"
[time]
disabled = false
format = '🕙 [$time]($style) '
time_format = '%m/%d %R'
[aws]
disabled = true
[gcloud]
disabled = true

sheldon
shellをfishではなくzshのままいくことにしたので、プラグイン入れていくのにsheldonを使うことにした。
brew install sheldon
sheldon init --shell zsh
.zshrcに以下を追記
eval "$(sheldon source)"
といってもautosuggestionsした今のところいれる予定はない

zsh-autosuggestinos
mizchiさんと同じようにAmazon Q Developer CLIのinline suggestionsを使おうと思ったのだけどterminalの背景色とサジェストされる文字の色が近くて見えなかった。
サジェストの色合いを変更できなそうだったのと、terminalの入力データの扱いがよくわからなかったこともあり素直にzsh-autosuggetionsを使うことにした。
環境変数でサジェストされる文字のスタイルを変更できるのでとりあえず見えるくらいの色合いに変更しておく。
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#767676"

fzf, z, bat, ezaなど
せっかくなので有名どころのツール 入れて使ってみる。
fzf
brew install fzf
z
これはsheldon経由でインストールする
[plugins.zsh-z]
github = "agkozak/zsh-z"
bat
brew install bat
雑にbatのaliasにcatの指定しておく
alias cat="bat"
eza
exaからezaに変わったらしい
brew install eza
これもalias設定しておく
# eza
alias ls="eza"
alias la="eza -a --git -g -h --oneline --icons"
alias ll="eza -al --git --icons --time-style relative"
こんな感じ

F-Sy-H(fast-Syntax-highlight)
zshのシンタックスハイライトするのにたぶん
これが一番使われてそうだけど、これより速いというfast-syntax-highlighというほうの プラグインを使おうと思ったのだけど似たようなリポジトリがいっぱいあってどれ使っていいかよくわからない。
よくわからないけどzshellのwikiっぽいところで紹介されてたやつを入れておく
[plugins.F-Sy-H]
github = "z-shell/F-Sy-H"
zshellってなんか違うやつっぽいな。まあ、でも使えてるからいいか