date
zshプロンプトでコマンドを実行できることを知っています。ただし、それは古い時間を示しています。現在の時刻を表示するには、ヒット<return>
して現在の時刻で新しいプロンプトを取得する必要があります。
zshプロンプトが毎秒常に更新されるように設定する方法はありますか?
注:同様の質問に対してこの回答を書きましたが、この質問のビューがどのように多いかを見て、ここに私の回答を再投稿すると便利だと思います。
これは実際、変なハックに頼らなくても可能です。これを.zshrcに入れました
RPROMPT='[%D{%L:%M:%S %p}]'
TMOUT=1
TRAPALRM() {
zle reset-prompt
}
TRAPALRM 関数は TMOUT 秒 (この場合は 1) ごとに呼び出され、ここでプロンプトの更新を実行し、コマンドの実行が開始されるまで実行します (Enter キーを押す前にプロンプトで入力したものに干渉しません)。
ソース: http://www.zsh.org/mla/users/2007/msg00944.html (2007 年のものです!)
私には嬉しいリクエストのように聞こえます。どちらかといえば、プロンプトが表示された時間を表示するよりも理にかなっています。
幸いなことに、Peter Stephenson がテクニックを投稿しました。.zshrc で次のようなことを試してください。
PROMPT="[%T] %n@%M %~ %# "
schedprompt() {
emulate -L zsh
zmodload -i zsh/sched
# Remove existing event, so that multiple calls to
# "schedprompt" work OK. (You could put one in precmd to push
# the timer 30 seconds into the future, for example.)
integer i=${"${(@)zsh_scheduled_events#*:*:}"[(I)schedprompt]}
(( i )) && sched -$i
# Test that zle is running before calling the widget (recommended
# to avoid error messages).
# Otherwise it updates on entry to zle, so there's no loss.
zle && zle reset-prompt
# This ensures we're not too far off the start of the minute
sched +30 schedprompt
}
schedprompt
これは .... 標準の zsh プロンプト (または bash やその他のシェル) では不快です。
Gnu Screen を使用したほうがよいと思います。
画面には、時間を表示できるステータス行を含めることができます。 screenrc の例を次に示します。「Red Hat Magazine A guide to GNU Screen」まで下にスクロールして、サンプル (ここで再現します) を確認します。このサンプルは、screen が実行されると、端末の右下隅に現在の時刻を表示します。
~/.screenrc
hardstatus alwayslastline hardstatus 文字列 '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f% t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W }%c %{g}]' # デフォルト画面 スクリーン -t shell1 0 スクリーン -t shell2 1