Closed9

shellをいい感じにする

ぱんだぱんだ

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

ぱんだぱんだ

fish, nushell

最初はzshのプラグインとかRust製のCLIツールとか入れるくらいに考えてたんだけどfishとかnushellといったものが気になってしまったので調べた。

fishに関しては以下の記事とかが参考になった

https://qiita.com/hennin/items/33758226a0de8c963ddf

nushellについて

https://zenn.dev/minedia/articles/6a8321fc6504ec

どっかでterminalの入力で補完効いているのをみていいなと思っていたらfishだとそれができるらしいと知って導入する気になった。また、fisherというパッケージマネージャーでfzfといった有名どころのツールも導入できそうだし、何よりそんなに設定作り込まなくてもすぐに導入できそうなのがいい感じ。

nushellはだいぶshell環境が別物になりそうな気がしたのでやめた。まだ、破壊的変更もありそうな気配がしたのとTerminalのWrapみたいな高機能ツール感を感じた。ghosttyみたいなシンプル、最低限のconfigで高機能みたいなツールのが好み。

ぱんだぱんだ

やっぱりzsh

1点だけ気になってたのがPOSIX非互換という点で、shell scriptがfishだと動かないとかそういうのあると面倒くさそうだなという点。実際、fishにしたけどzshに戻したみたいな記事を書いている人はけっこういた。

https://zenn.dev/mizchi/scraps/8969fe29a27e21

いろいろ記事まさぐっていたらmizshiさんのスクラップ出てきて補完だけ欲しいならzshのままでもできるということを知ったのでzshのままいくことにしました。

ぱんだぱんだ

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

ぱんだぱんだ

Starship

これはfish調べているときに知って、導入も簡単そうだったので入れてみる。

https://arc.net/l/quote/qymrldhu

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
ぱんだぱんだ

zsh-autosuggestinos

https://github.com/zsh-users/zsh-autosuggestions

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

https://zenn.dev/nokogiri/articles/ec99e40df54555

z

https://github.com/agkozak/zsh-z

これはsheldon経由でインストールする

~/.config/sheldon/plugins.toml
[plugins.zsh-z]
github = "agkozak/zsh-z"

bat

https://github.com/sharkdp/bat

brew install bat

雑にbatのaliasにcatの指定しておく

alias cat="bat"

eza

exaからezaに変わったらしい

https://github.com/eza-community/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のシンタックスハイライトするのにたぶん

https://github.com/zsh-users/zsh-syntax-highlighting

これが一番使われてそうだけど、これより速いというfast-syntax-highlighというほうの プラグインを使おうと思ったのだけど似たようなリポジトリがいっぱいあってどれ使っていいかよくわからない。

https://github.com/zdharma-continuum/fast-syntax-highlighting

https://github.com/zdharma/fast-syntax-highlighting

https://github.com/z-shell/F-Sy-H

よくわからないけどzshellのwikiっぽいところで紹介されてたやつを入れておく

https://wiki.zshell.dev/ja/ecosystem/plugins/f-sy-h

~/.config/sheldon/sheldon.toml
[plugins.F-Sy-H]
github = "z-shell/F-Sy-H"

zshellってなんか違うやつっぽいな。まあ、でも使えてるからいいか

このスクラップは17日前にクローズされました