6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

macOSでプロンプトに時刻表示

Last updated at Posted at 2022-04-06

経緯

  • マシンをつけっぱなしにしている
  • とある時間のかかるコマンドの実行結果が、実行→一寝入り→起きる→いつの実行だったか分からなくなる事態が発生した

環境

macOS Monterey 12.3
(macOS Ventura 13.0 も :ok:
(macOS Sonoma 14 も :ok:
zsh

時間情報等は普通に記録されてました :bow:

特に何も設定していなくても、

history -i

でコマンド実行時刻が表示されます。

他にもオプションがあり、 -D で実行時間も表示されます。

% history -iD | tail
13212  2024-05-19 16:56  0:11  sleep 11

変更する前のプロンプト(書式未設定)

takepan@MBP16 current_dir %

変更した後のプロンプト

22-04-06 13:43:56 takepan@MBP16 ~/current_path %

.zshrcに追記した書式

PROMPT='%D %* %n@%m %~ %% '

コマンド例

echo "PROMPT='%D %* %n@%m %~ %% '" >> ~/.zshrc
source ~/.zshrc

問題点

0時〜9時のときに0パディングがされない
(0パディングのオプションがなさそう)

参考URL

zshプロンプトのカスタマイズ
Macのターミナルのプロンプト表示(ユーザー名等)を変更する方法
公式ドキュメント?

6
3
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
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?