grasys blog

ターミナルがダサいとモテない。Starship 紹介編

Starship をお使いですか?

Photo by Andy Hermawan on Unsplash

恵比寿で IT 企業をやっているとモテると聞いて創業しましたが早いことありがたいことに10年目に突入した長谷川です。

まだモテる成果は出ていません、、、これからです!(3回目)

最近、歳なのか夜が眠れません・・・
眠れない夜にスマホアプリで少しずつ書いているのがあるので公開していきます。

シリーズ記事一覧

Starship

自分は mac の中で Bash の Command-Line Framework の rerun を使っているため、zsh に移行できてません
rerun には macOS の設定やら業務上で利用する Script などを登録しているので無くすのがとても難しい・・・
かといって Shell でできることを Python の Typer とかで置き換えるのもちょっと・・・

Prompts をいじって見た目を工夫したり、もう何年前だろうか・・・
20年前くらいにこだわってた若かりし頃がありますが今なら Starship で一発ですね。

Starship の特徴(ざっくり)

  • Rust で書かれている
  • めちゃくちゃカスタマイズできる
  • CWD の状態を表示できる。
  • どんな Shell でもどの OS でも動く
  • Config も体系化されてて簡単

Starship: Cross-Shell Prompt


慣れると他のホストでちょっとさみしく感じるくらい見た目が派手です。

Starship


ちなみにこの System Infomation は neofetch です。

普通に mac の homebrew にあります。

GitHub – dylanaraps/neofetch: 🖼️ A command-line system information tool written in bash 3.2+

Install Nerd Fonts

まず Nerd Fonts を Install する必要があります。

Nerd Fonts – Iconic font aggregator, glyphs/icons collection, & fonts patcher


こちらも以下のコマンドで homebrew から Install できます。

tap で homebrew/cask-fonts を有効化します。
以下の例では Hack Nerd Font を入れています。

brew tap homebrew/cask-fonts
brew install font-hack-nerd-font

GitHub – ryanoasis/nerd-fonts: Iconic font aggregator, collection, & patcher. 3,600+ icons, 50+…

nerd-fonts は好みで良いかと


github monaspace

Monaspace


moralerspace

自分はこちらを利用しています。

GitHub – yuru7/moralerspace: Moralerspace は、欧文フォント Monaspace と日本語フォント IBM Plex Sans JP…


HackGen

GitHub – yuru7/HackGen: Hack と源柔ゴシックを合成したプログラミングフォント 白源 (はくげん/HackGen)

Install Starship

Starship も homebrew にあります。

以下のコマンドで Install できます。

brew install starship

Setup shell

bash

bash なら以下のように ~/.bashrc などに設定してください。

if command -v starship &> /dev/null; then
eval "$(starship completions bash)"
eval "$(starship init bash)"
fi


zsh

自分は zsh を利用していないので Official を参考に

Starship: Cross-Shell Prompt

Configuration

ここからが設定です。

starship のサブコマンドには print-config がありそれを使うことで default の設定を出力できます。

まず以下のコマンドで default 設定を出力しちゃいましょう!

test ! -d ${HOME}/.config && mkdir ${HOME}/.config
test ! -f ${HOME}/.config/starship.toml && starship print-config --default > ${HOME}/.config/starship.toml

Document はこちらです。

Starship: Cross-Shell Prompt

Prompt

ここから詳細な設定に入ります。自分の変更している箇所を説明していきます。

まずは、Prompt の設定です。

Starship: Cross-Shell Prompt


自分の Starship の Prompt はこんな感じです。

Apple Color Emoji を普通に使ってしまっていますが、問題は発生してません。
発生したら Nerd Font に切り替えますw

starship prompt


以下のこれらだけそれぞれの設定において色付けや表示面のカスタマイズをしています。

  • $username
  • $os
  • $hostname
  • $memory_usage
  • $time
  • $battery
  • $directory
  • $cmd_duration

Pastel Powerline Preset を使っていて、配色を Dracula に合わせています。

当たり前だけど、残念ながら Nerd Fonts の記号がこの HTML で表現できず・・・😅

format = """
[](#9A348E)$username$os$hostname$localip[](fg:#9A348E bg:#DA627D)$memory_usage[](fg:#DA627D bg:#FCA17D)$time[](fg:#FCA17D bg:#06969A)$battery[](fg:#06969A bg:#33658A)$directory[](fg:#33658A bg:#86BBD8)$cmd_duration[ ](fg:#86BBD8)\
$shell$shlvl$singularity$kubernetes$vcsh$fossil_branch$git_branch$git_commit$git_state$git_metrics$git_status$hg_branch$pijul_channel$docker_context$package$bun$c$cmake$cobol$daml$dart$deno$dotnet$elixir$elm$erlang$fennel$golang$gradle$haskell$haxe$helm$java$julia$kotlin$lua$nim$nodejs$ocaml$opa$perl$php$pulumi$purescript$python$raku$rlang$red$ruby$rust$scala$solidity$swift$terraform$vlang$vagrant$zig$buf$guix_shell$nix_shell$conda$meson$spack$aws$gcloud$openstack$azure$direnv$env_var$crystal$custom$sudo$line_break$jobs$status$container$character
"""

Starship: Cross-Shell Prompt


$username

[username]
format = "[$user ]($style)"
style_root = "bg:#9A348E"
style_user = "bg:#9A348E"
show_always = true
disabled = false

Starship: Cross-Shell Prompt


$os

[os]
format = "[$symbol]($style)"
style = "bg:#9A348E"
disabled = false

print-config で出力された toml を見ると、いろいろな OS の Icon が設定されているのでちょっと楽しいです。

Starship $os.symbols

Starship: Cross-Shell Prompt


$hostname

[hostname]
ssh_only = false
ssh_symbol = "🌐"
trim_at = "."
detect_env_vars = []
format = "[$ssh_symbol$hostname ]($style)"
style = "bg:#9A348E"
disabled = false

Starship: Cross-Shell Prompt


$memory_usage

[memory_usage]
threshold = -1
format = "[$symbol$ram_pct ]($style)"
style = "bg:#DA627D"
symbol = "🧛 "
disabled = false

Starship: Cross-Shell Prompt


$time

[time]
format = "[ 🕒 $time ]($style)"
style = "fg:#191970 bg:#FCA17D"
use_12hr = false
time_format = "%T"
disabled = false
utc_time_offset = "local"
time_range = "-"

Starship: Cross-Shell Prompt


$battery

[battery]
full_symbol = "🔋"
charging_symbol = "🔌"
discharging_symbol = "🪫"
unknown_symbol = "❓ "
empty_symbol = "🧟 "
disabled = false
format = "[ $symbol$percentage ]($style)"

[[battery.display]]
threshold = 100
style = "bg:#06969A"

[[battery.display]]
threshold = 30
style = "bg:#06969A"
discharging_symbol = "💦"

Starship: Cross-Shell Prompt


$directory

[directory]
truncation_length = 3
truncate_to_repo = true
fish_style_pwd_dir_length = 0
use_logical_path = true
format = "[ 📁 $path ]($style)[$read_only]($read_only_style)"
repo_root_format = "[ $before_root_path ]($before_repo_root_style)[$repo_root]($repo_root_style)[$path]($style)[$read_only]($read_only_style)"
style = "bg:#33658A"
disabled = false
read_only = "🔒"
read_only_style = "red"
truncation_symbol = ".../"
home_symbol = "~"
use_os_path_sep = true

Starship: Cross-Shell Prompt


$cmd_duration

[cmd_duration]
min_time = 2000
format = "[ 🐢 $duration ]($style)"
style = "fg:#DA627D bold bg:#86BBD8"
show_milliseconds = false
disabled = false
show_notifications = false
min_time_to_notify = 5000

🐢入れてますw

Starship: Cross-Shell Prompt


git の directory などでプロンプトに状態がでるので便利です。

Starship: Cross-Shell Prompt


先日の Update で Direnv も取り込まれました。

chore(master): release 1.17.1 (#5670) · starship/starship@1082afc


Starship は邪魔になったら .bashrc の設定ですぐ外せるし、ちょっと見た目が知らない人からすると「おっ!」ってなると思うのでオススメw

(ただし Remote と macOS Local の表示の違いが気持ち悪さに繋がります・・・)

他にもシリーズ記事を書いているので、よろしければご覧ください!

シリーズ記事一覧


採用情報
お問い合わせ