Starshipプロンプトの設定・カスタマイズ完全ガイド
Starshipプロンプトの設定方法からカスタマイズ、Git表示、テーマ変更までを詳しく解説。初心者でも簡単に美しいプロンプトを導入できます。
Starshipとは?
Starshipは、シェルプロンプトを美しく、情報豊富にカスタマイズできるツールです。Rustで書かれており、高速で、あらゆる主要シェル(Bash、Zsh、Fish、PowerShell)に対応しています。デフォルトのプロンプトはミニマルですが、豊富な設定オプションで自分好みに変更できます。
インストール方法
macOS / Linux
curl -sS https://starship.rs/install.sh | sh
Windows(PowerShell)
winget install --id Starship.Starship
またはScoopを使う場合:
scoop install starship
その他の方法
公式サイト(https://starship.rs/)に詳細なインストール手順があります。シェルへの設定追加
インストール後、使用しているシェルの設定ファイルに以下の行を追加します。
Bash
~/.bashrc の末尾に追加:
eval "$(starship init bash)"
Zsh
~/.zshrc の末尾に追加:
eval "$(starship init zsh)"
Fish
~/.config/fish/config.fish の末尾に追加:
starship init fish | source
PowerShell
$PROFILE の末尾に追加:
Invoke-Expression (&starship init powershell)
シェルを再起動すると、デフォルトのStarshipプロンプトが表示されます。
設定ファイルの基本
Starshipの設定は ~/.config/starship.toml にTOML形式で記述します。デフォルトの設定はこのファイルがない場合に適用されます。
設定ファイルの例:
<h1>プロンプトの先頭に改行を入れる</h1>
add_newline = true
<h1>コマンド実行時間を表示</h1>
[cmd_duration]
min_time = 2000
show_milliseconds = false
<h1>Git情報を表示</h1>
[git_branch]
symbol = "🌱 "
style = "bold green"
[git_status]
conflicted = "🏳"
ahead = "⇡${count}"
behind = "⇣${count}"
主要なモジュールのカスタマイズ
プロンプト全体の書式
format オプションでプロンプトの表示順序や内容を自由に変更できます。
format = """
[](#9A348E)
$os$
$username$
[](#DA627D)
$directory$
[](#FCA17D)
$git_branch$
$git_status$
$cmd_duration$
$character
"""
Git表示の詳細設定
Gitリポジトリ内でのブランチ名や状態をカスタマイズできます。
[git_branch]
<h1>ブランチ名の最大長</h1>
truncation_length = 15
<h1>切り詰め記号</h1>
truncation_symbol = "…"
[git_status]
<h1>各種状態の表示記号</h1>
staged = "➕"
modified = "✏️"
untracked = "❓"
ディレクトリ表示
カレントディレクトリの表示を調整します。
[directory]
truncation_length = 3
<h1>ホームディレクトリを ~ と表示</h1>
truncate_to_repo = true
<h1>パス区切り文字</h1>
style = "bold cyan"
タイムスタンプ
コマンドの実行時間を表示できます。
[cmd_duration]
min_time = 5000 # 5秒以上の場合のみ表示
style = "yellow"
テーマの適用
コミュニティが作成したテーマを簡単に適用できます。代表的なテーマを紹介します。
Tokyo Night
<h1>公式テーマリポジトリからコピー</h1>
<h1>https://github.com/starship/starship/blob/master/docs/presets/README.md</h1>
Pastel Powerline
[character]
success_symbol = "▶"
error_symbol = "▶"
テーマは設定ファイルに直接貼り付けるか、starship preset コマンドで適用できます。
starship preset tokyo-night -o ~/.config/starship.toml
トラブルシューティング
プロンプトが表示されない
starship --version でインストールを確認starship explain で診断)特殊文字が文字化けする
Git情報が遅い
git_status の disabled を一時的に設定[git_status]
disabled = true
まとめ
Starshipを使えば、シェルプロンプトを簡単にカスタマイズできます。設定ファイルを編集するだけで、Git情報、実行時間、ディレクトリなどを自由に表示できます。公式ドキュメント(https://starship.rs/config/)も充実しているので、ぜひ自分好みのプロンプトを作成してみてください。