Show a timestamp on the right side of prompt when executing a command in ZSH
+2
−0
How to configure ZSH shell to print a timestamp on the right hand side of the prompt line when executing a command? I don't want to display the time prior to executing a command.
Here's about how it should look like (just a very basic prompt for illustration):
[me@pc ~]$ echo Have you tried StreetComplete? [10:24:07]
Have you tried StreetComplete?
[me@pc ~]$
Presumably something in .zshrc
file should do the trick.
1 answer
+2
−0
The preexec
function is called right before executing commands, so it's the place to do this sorta things.
This solution is adapted from Dan Berindei's original answer (CC BY-SA 3.0) to a related question:
preexec () {
TIME=`date +"[%H:%M:%S]"`
C=$(($COLUMNS-12))
echo -e "\033[1A\033[${C}C ${TIME} "
}
Just paste it in your .zshrc
file.
It uses ANSI excape codes to print the timestamp to the previous line (prompt line). Note that you will likely need to modify the columns count if you change the timestamp format.
0 comment threads