LoginSignup
9
6

More than 5 years have passed since last update.

Zshでコマンドの終了ステータス コードをプロンプトに表示する

Last updated at Posted at 2013-01-29

直前に実行したコマンドとその終了ステータス コードをプロンプトに表示します。
promptsubst を有効にして $history[$(($HISTCMD-1))] で直前のコマンドを取り出します。
本質ではありませんが、背景色を $?=0 のときは緑、それ以外のときは赤くしてみました。

シェル スクリプトの作成時に各コマンドの終了ステータス コードを調べるときや、
実行するすべてのコマンドの終了ステータス コードが気になる人(自分のこと)にオススメ。

autoload -U colors
colors
setopt promptsubst
PROMPT="%{$fg[black]%(?.$bg[green].$bg[red])%}<%?> \$history[\$((\$HISTCMD-1))]%{$reset_color%}
(%n@%m)[%h] %~ %% "
9
6
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
9
6