Skip to main content

Shell prompt with timestamps

I just needed a my shell prompt to display the current time, with a bit more precision than seconds, but I did not need all the nanoseconds GNU/date offered me:

  PS1='$(date +%H:%M:%S.%N | sed "s/.\{5\}$//") \u@\h$ '
Of course with bash-v3 there's HISTTIMEFORMAT, which will save timestamps to HISTFILE anyway, but this time I wanted it to be displayed as I typed.