fish(friendly interactive shell)はユーザフレンドリーなコマンドラインシェルです。シェルをfishに切り替えてみました。
またプロンプトを装飾するためにStarshipを使ってみました。

情報

環境

  • OS / Shell / プロンプト
    • Arch Linux / fish /starship
    • Ubuntu / fish / starship
    • Windows - WSL - Ubuntu / fish / starship
    • Windows / CMD / starship
    • Windows / PowerShell / starship
  • ターミナルソフト
    • GNOME Termnal
    • Windows Terminal
  • フォント
    • HackGen Console NF

fish構築

  1. インストール
  • Arch Linuxの場合
    sudo pacman -S fish
  • Ubuntuの場合
    sudo apt install fish
  1. 起動設定
  1. fishの設定

    fish_config

    [Enter]キーで終了

  2. グリーティングを無効化

    set -U fish_greeting
  3. 環境設定ファイル
    Ubuntuの場合はコマンドの色が暗いので以下に変更した方がよいかもしれない。

    ~/.config/fish/config.fish
    set fish_color_command        brcyan

fishプラグイン

  • プラグイン管理 fisher
    https://github.com/jorgebucaran/fisher

    curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher
  • z
    ディレクトリ名を指定して直接移動

    fisher install jethrokuan/z
  • fzf
    Ctrl+Rでコマンド履歴検索

    sudo pacman -S fzf
    fisher install PatrickF1/fzf.fish

Starship構築

Starshipはクロスプラットフォーム対応のシェルプロンプト
https://github.com/starship/starship/blob/master/docs/ja-JP/guide/README.md

Arch Linux

  1. Nerd Fontのインストール

    paru -S ttf-hackgen

    ターミナルソフトのフォントをHackGen Console NFに設定する。

  2. Starshipのインストール

    sudo pacman -S starship
  3. Starshipの有効化

    ~/.config/fish/config.fish
    starship init fish | source
  4. テーマの適用

    starship preset tokyo-night -o ~/.config/starship.toml

Ubuntu

  1. Nerd Fontのインストール
    https://github.com/yuru7/HackGen/releases
    HackGen_NF_v2.9.0.zipをダウンロードして展開したttfファイルを~/.fonts/フォルダに格納
    ターミナルソフトのフォントをHackGen Console NFに設定する。

  2. Starshipのインストール

    • WSLの場合
      標準のrustcが古いのでRustupからインストールする
      curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
      This is usually done by running one of the following (note the leading DOT):
      . "$HOME/.cargo/env" # For sh/bash/zsh/ash/dash/pdksh
      source "$HOME/.cargo/env.fish" # For fish
      source "$HOME/.cargo/env.fish"
      cargo install starship --locked
    • WSLではない場合
      sudo apt install cargo build-essential cmake
      source "$HOME/.cargo/env.fish"
      cargo install starship --locked
  3. Starshipの有効化

    ~/.config/fish/config.fish
    starship init fish | source
  4. テーマの適用

    starship preset tokyo-night -o ~/.config/starship.toml

Windows

  1. Nerd Fontのインストール
    以下からインストール
    https://github.com/yuru7/HackGen/releases

  2. Starshipのインストール

    winget install clink starship
    clink autorun install -- --quiet
  3. Starshipの有効化

  • Windows / CMDの場合
    %LocalAppData%\clink\starship.lua
    load(io.popen('starship init cmd'):read("*a"))()
  • Windows / PowerShellの場合
    $PROFILE
    Invoke-Expression (&starship init powershell)
  1. テーマの適用
    mkdir %USERPROFILE%\.config
    starship preset tokyo-night -o %USERPROFILE%\.config\starship.toml

Starshipカスタマイズ

スクリーンショット

  • Arch Linux
  • Ubuntu (WSL)
  • Windows / CMD
  • Windows / PowerShell

テーマのカスタマイズ

  • tokyo-nightテーマがベース
  • OSアイコンとユーザ名を表示
  • ホスト名は表示しない
  • CMDとPowerShellを区別するためにPowerShellはPSと表示
  • sudoキャッシュが有効な期間は工具箱アイコンを表示
    ~/.config/starship.toml
    format = """
    [░▒▓](#a3aed2)\
    [ $os$username$sudo](bg:#a3aed2 fg:#090c0c)\
    [](bg:#769ff0 fg:#a3aed2)\
    $directory\
    [](fg:#769ff0 bg:#394260)\
    $git_branch\
    $git_status\
    [](fg:#394260 bg:#212736)\
    $nodejs\
    $rust\
    $golang\
    $php\
    [](fg:#212736 bg:#1d2230)\
    $time\
    [ ](fg:#1d2230)\
    \n$shell$character"""

    [directory]
    style = "fg:#e3e5e5 bg:#769ff0"
    format = "[ $path ]($style)"
    truncation_length = 3
    truncation_symbol = "…/"

    [git_branch]
    symbol = ""
    style = "bg:#394260"
    format = '[[ $symbol $branch ](fg:#769ff0 bg:#394260)]($style)'

    [git_status]
    style = "bg:#394260"
    format = '[[($all_status$ahead_behind )](fg:#769ff0 bg:#394260)]($style)'

    [nodejs]
    symbol = ""
    style = "bg:#212736"
    format = '[[ $symbol ($version) ](fg:#769ff0 bg:#212736)]($style)'

    [rust]
    symbol = ""
    style = "bg:#212736"
    format = '[[ $symbol ($version) ](fg:#769ff0 bg:#212736)]($style)'

    [golang]
    symbol = ""
    style = "bg:#212736"
    format = '[[ $symbol ($version) ](fg:#769ff0 bg:#212736)]($style)'

    [php]
    symbol = ""
    style = "bg:#212736"
    format = '[[ $symbol ($version) ](fg:#769ff0 bg:#212736)]($style)'

    [time]
    disabled = false
    time_format = "%R" # Hour:Minute Format
    style = "bg:#1d2230"
    format = '[[  $time ](fg:#a0a9cb bg:#1d2230)]($style)'

    [username]
    show_always = true
    style_user = "bg:#a3aed2 fg:#090c0c"
    style_root = "bg:color_orange fg:color_fg0"
    format = '[ $user ]($style)'

    [os]
    disabled = false
    style = "bg:#a3aed2 fg:#090c0c"

    [os.symbols]
    Windows = "󰍲"
    Ubuntu = "󰕈"
    SUSE = ""
    Raspbian = "󰐿"
    Mint = "󰣭"
    Macos = "󰀵"
    Manjaro = ""
    Linux = "󰌽"
    Gentoo = "󰣨"
    Fedora = "󰣛"
    Alpine = ""
    Amazon = ""
    Android = ""
    Arch = "󰣇"
    Artix = "󰣇"
    EndeavourOS = ""
    CentOS = ""
    Debian = "󰣚"
    Redhat = "󱄛"
    RedHatEnterprise = "󱄛"

    [shell]
    fish_indicator = ''
    powershell_indicator = 'PS'
    cmd_indicator = ''
    unknown_indicator = ''
    style = 'cyan bold'
    disabled = false

    [sudo]
    format = '$symbol'
    style = 'bg:#a3aed2 fg:#090c0c'
    symbol = '🧰'
    allow_windows = true
    disabled = false