LoginSignup
2
0

More than 5 years have passed since last update.

[fish shell] 終了ステータスを常に表示する

Posted at

背景

grep no_exit_text sample/で失敗しても何もエラーが返してこないので、ハマっていました!コマンドを実行後の終了ステータスを常に知っておきたいです!

  • macOS Mojave 10.14.2
  • fish, version 3.0.0

fish shellはめちゃ簡単にできます!

実装

~/.config/fish/functions/fish_prompt.fish
function fish_prompt --description 'Write out the prompt'
    set exit_status $status
    if test "$exit_status" -eq 0
        set status_color normal
    else
        set status_color red
    end

    if test -z $WINDOW
        printf '%s%s@%s%s%s%s: %s%d%s> ' (set_color yellow) (whoami) (set_color purple) (prompt_hostname) (set_color $fish_color_cwd) (prompt_pwd) (set_color $status_color) $exit_status (set_color normal)
    else
        printf '%s%s@%s%s%s(%s)%s%s: %s%d%s> ' (set_color yellow) (whoami) (set_color purple) (prompt_hostname) (set_color white) (echo $WINDOW) (set_color $fish_color_cwd) (prompt_pwd) (set_color $status_color) $exit_status (set_color normal)
    end
end

正常終了のときにはnormalの色で、エラーの時には赤で表示されます。以下のようです。

Screen Shot 2019-02-01 at 14.28.59.png

2
0
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
0