やりたいこと
プロンプトの右側にコマンドを実行した時刻を残したい。でも、現在のプロンプトには時刻の代わりに、gitのブランチとかの情報を表示したい。
解決策
precmd
フックとaccept-line
を使って、RPROMPT
変数を交互に書き換えてやるとよいです。
.zshrc
# setopt等は適当にやってある
# 現在のプロンプトにはVCSの情報を表示
current-rprompt() {
RPROMPT='${vcs_info_msg_0_}'
}
add-zsh-hook precmd current-rprompt
# 以前のプロンプトにはコマンドラインを確定した時刻を表示
update-rprompt-accpet-line() {
RPROMPT='%D{%y/%m/%d %H:%M:%S}'
zle .reset-prompt
zle .accept-line
}
zle -N accept-line update-rprompt-accpet-line