Ubuntuでbashからzshに変更して見た目もかっこよくする
- zsh のインストール
sudo apt update
sudo apt install zsh- zsh の確認
zsh --version- デフォルトシェルを zsh に変更
chsh -s $(which zsh)コマンド実行後は再ログインか再起動が必要です。
- Rust 環境構築
NOTE
Rust 環境は構築しなくてもcurlなどを使うことでプラグインをインストールできますが、私はインストールをすべてcargoに揃えたかったので構築しました。cargoを使わずに設定したい場合は公式サイトを参照ください。
見た目の変更などに rust のパッケージを使用するので、コンパイルに必要なパッケージをインストールします。
build-essentialにいろいろ入っているみたいですが、それだけだとエラーになったので追加でインストールします。
sudo apt install build-essential
sudo apt install pkg-config
sudo apt install libssl-dev
sudo apt install cmake以下のコマンドを実行すると選択肢が出てきますが、そのまま Enter で OK です。
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shインストールが完了したらターミナルを再起動します。
バージョン表示してインストールできているか確認します。
rustup -V
cargo -V- Starship インストール
Starshipとはシェル用のプロンプト?で簡単に見た目のカスタマイズができます。
公式サイト https://starship.rs/ja-JP/
cargo install starship --lockedターミナルに反映させるために.zshrcの末尾に以下を追加
eval "$(starship init zsh)"starship の設定ファイルを作成します
starship config上記コマンドでviモードになるので、設定後はZZで変更して保存できます。
私は以下のように設定しました。 その他の設定項目は公式サイトをご覧ください。
https://starship.rs/ja-JP/config/
# エディターの補完を設定スキーマに合わせて取得
"$schema" = 'https://starship.rs/config-schema.json'
add_newline = true
[directory]
format = "[$path]($style) "
truncation_length = 8
truncation_symbol = "..."
truncate_to_repo = false
[git_branch]
format = "on [$symbol$branch]($style) "
[bun]
format = "via [$symbol$version]($style) "
[nodejs]
format = "via [$symbol$version]($style) "
detect_extensions = ["js", "mjs", "cjs", "ts", "mts", "cts"]
detect_files = ["package.json", ".node-version", "!bunfig.toml", "!bun.lockb"]
detect_folders = ["node_modules"]- Nerd Font インストール
Nerd Fontをインストールすることで、StarShip で使用するフォントの文字化けを防げます。
以下のサイトからダウンロードできます。
https://www.nerdfonts.com/font-downloads
私はCaskaydiaCove Nerd Fontをインストールしました。
フォントは好きなものを選んでください。
- Sheldon インストール
Sheldonはプラグインマネージャーで、Rust 製で高速に動作します。
cargo install sheldon以下コマンドで設定ファイルを作成します。
$XDG_CONFIG_HOMEを変更していなかったら、~/.config/sheldon/plugins.tomlに作成されます。
質問を聞かれますが yes で OK です。
sheldon init --shell zsh通常の設定では.zshrcファイルにeval "$(sheldon source)"を記述しますが、それだと起動のたびに呼び出されるため時間がかかってしまいます。
そのためキャッシュすることによって起動を高速化しています。
# ファイル名を変数に入れる
cache_dir=${XDG_CACHE_HOME:-$HOME/.cache}
sheldon_cache="$cache_dir/sheldon.zsh"
sheldon_toml="$HOME/.config/sheldon/plugins.toml"
# キャッシュがない、またはキャッシュが古い場合にキャッシュを作成
if [[ ! -r "$sheldon_cache" || "$sheldon_toml" -nt "$sheldon_cache" ]]; then
mkdir -p $cache_dir
sheldon source > $sheldon_cache
fi
source "$sheldon_cache"
# 使い終わった変数を削除
unset cache_dir sheldon_cache sheldon_tomlsheldonで取り合えず 2 つプラグインを入れました。
[plugins.zsh-syntax-highlighting]
github = "zsh-users/zsh-syntax-highlighting"
[plugins.zsh-autosuggestions]
github = "zsh-users/zsh-autosuggestions"参考サイト
