2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Progate Path コミュニティAdvent Calendar 2023

Day 13

【starship】ターミナルをかっこよく

Last updated at Posted at 2023-12-13

/darallium/です!ご覧いただきありがとうございます. 😊

「CLI初心者でも感動するような,それでいて汎用性・拡張性の高いCLIツール」を紹介する7日間の6日目の記事です 🙇

本日は「味気ないターミナルをかっこよく」をテーマに,starshipを紹介します:relaxed:

starship

image.png
starshipとは,ターミナルのプロンプトをお手軽にいじるためのツールである.

installation

dependencies

  • nerdfont
  • [windows] clink

windows

winget install --id Starship.Starship

※clinkのみ
終了時に,%LocalAppData%\clink\starship.lua
load(io.popen('starship init cmd'):read("*a"))()

linux macOS

curl -sS https://starship.rs/install.sh | sh

叩いたときに,各shellの設定が出てくるので,それを.bashrcなどに記述する.

見た目をチューニングする

image.png

linuxでは~/.config/starship.toml,windowsでは%appdata%\starship.tomlで設定ファイルを記述できる.

まず全体を設定し, 次に書く項目を設定し,つなぎ合わせることでプロンプトが完成する.

基本概念

  • format: 表示する項目を列挙することができる.ここで指定した順序でプロンプトが表示される.
    • 末尾に\を置くことで,改行せずに横に並べる指令になる.
    • 空行は空行として出力される.
    • 文字を出力したい場合,文字列と指定することで,色付きに出力することができる.
列挙可能な項目
- username - hostname - localip - shlvl - singularity - kubernetes - directory - vcsh - fossil_branch - git_branch - git_commit - git_state - git_metrics - git_status - hg_branch - pijul_channel - docker_context - package - c - cmake - cobol - daml - dart - deno - dotnet - elixir - elm - erlang - fennel - golang - guix_shell - haskell - haxe - helm - java - julia - kotlin - gradle - lua - nim - nodejs - ocaml - opa - perl - php - pulumi - purescript - python - raku - rlang - red - ruby - rust - scala - solidity - swift - terraform - vlang - vagrant - zig - buf - nix_shell - conda - meson - spack - memory_usage - aws - gcloud - openstack - azure - env_var - crystal - custom - sudo - cmd_duration - line_break - jobs - battery - time - status - os - container - shell - character -
  • right_format: 入力と同じ行にレンダリングされる右プロンプトを指定できる.書式はformatに同じだが,単一の行でなければならない.
  • add_newline: プロンプトから見て入力行を改行した先の行に置く

各種項目

共通部分だけ乗せる.

  • style: カラーコードで最も一般的なものを1つだけ記述できる
  • format: その項の形式を示すことができる

各種項目には変数と設定項目があり,設定項目 = 値で設定でき,変数は$変数名で引っ張ってこれる.

具体的に各項目の設定は,公式ドキュメントを見るとよい.

いかに筆者の例を表示する.

details
#                                     

format = """
[ ](bg:#585858)\
$os\
$battery(bg:#CCCC11 fg:#1111CC)\
$username\
[](bg:#444444 fg:#585858)\
$hostname\
[](bg:#0087AF fg:#444444)\
$directory\
[](fg:#0087AF) \
$fill\
$git_branch\
$git_status\
$git_commit\
$nodejs\
$rust\
$localip
$character
"""

# Disable the blank line at the start of the prompt
add_newline = true

[battery]
full_symbol='󰁹'
empty_symbol=''
charging_symbol='󰂄'
discharging_symbol='󰂀'
unknown_symbol='󰂑'
format = '[$symbol$percentage](red) '


[character]
success_symbol = '[────>](bold green) '
error_symbol = '[✗](bold red) '

[linebreak]
disable = true

# You can also replace your username with a neat symbol like   or disable this
# and use the os module below
[username]
show_always = true
style_user = "bg:#585858"
style_root = "bg:#585858"
format = '[$user ]($style)'
disabled = false


# An alternative to the username module which displays a symbol that
# represents the current operating system
[os]
style = "bg:#585858"
disabled = true # Disabled by default

[fill]
symbol = " "

[hostname]
ssh_only = true
style = "bg:#444444"
ssh_symbol = ''
format = '[$ssh_symbol]($style)[ on ]($style)[$hostname](fg:red bg:$style)'

[directory]
style = "fg:#303030 bg:#0087AF"
read_only = ''
read_only_style="fg:#AF0000 bg:#0087AF"
format = '[ $path ]($style)[$read_only]($read_only_style)'
truncation_length = 5
truncation_symbol = ":"
truncate_to_repo = true
home_symbol = '󰋜'
use_os_path_sep = false

# Here is how you can shorten some long paths by text replacement
# similar to mapped_locations in Oh My Posh:
[directory.substitutions]
"Documents" = " "
"Downloads" = " "
"Music" = " "
"Pictures" = " "
# Keep in mind that the order matters. For example:
# "Important Documents" = "  "
# will not be replaced, because "Documents" was already substituted before.
# So either put "Important Documents" before "Documents" or use the substituted version:
# "Important  " = "  "


[c]
symbol = " "
style = "bg:#444444"
format = '[ $symbol ($version) ]($style)'

[docker_context]
symbol = " "
style = "bg:#06969A"
format = '[ $symbol $context ]($style) $path'
[git_branch]
symbol = ""
style = "fg:#303030 bg:#CF9562"
format = '[](fg:#CF9562)[ $symbol $branch ]($style)'

[git_status]
style = "bg:#CF9562 fg:#444444"
conflicted = '󰞇=\($count\)'
ahead = '🏎💨'
behind = '😰'
diverged = '😵'
up_to_date = '✓'
untracked = '🤷'
stashed = '📦=\($count\)'
modified = '📝'
staged = '[s=\($count\)](bg:#CF9562 fg:#444444)'
renamed = '👅'
deleted = '🗑'
format = '[$all_status$ahead_behind ]($style)[](bg:#CF9562 fg:#303030 fg:#444444)'

[git_commit]
style = "bg: #CF9562"
commit_hash_length = 4
tag_symbol = '🔖 '

[localip]
style = "bg:#CF9562 fg:#444444"
ssh_only = false
format = '[$localipv4]($style) '
disabled = false

[memory_usage]
disabled = false
threshold = -1
symbol = ' '
style = "bg:#CF9562 fg:#444444"

[julia]
symbol = " "
style = "bg:#444444"
format = '[ $symbol ($version) ]($style)'

[nodejs]
symbol = ""
style = "bg:#444444"
format = '[ $symbol ($version) ]($style)'

[rust]
symbol = ""
style = "bg:#444444"
format = '[ $symbol ($version) ]($style)'

あとがき

シェルがかっこよくなることで開発モチベが上がる.また,シェルの良さには人それぞれあり,個性が出る.「右側にプロンプトあるの使いにくくない?」という人もいるし,「それはアシンメトリーがああだこーだでカッコいいかもね」という人もいる.自分好みの設定にして最高のターミナル環境を経験しよう.余談だが,Starshipのドキュメントは日本語化されていて非常に読みやすいうえ,充実しているのでじっくり読んでみることをお勧めする.

referencing

Ritsumeikan security circle B2生の先輩方

2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?