2 ms·
I have a much shorter snippet in .profile for bash: if $INTERACTIVE; then # http://superuser.com/a/175802 # show date when command was executed
by akavel 7y ago
I have a much shorter snippet in .profile for bash:
if $INTERACTIVE; then
# http://superuser.com/a/175802
# show date when command was executed
preexec() {
[ -n "$COMP_LINE" ] && return # do nothing if completing
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # don't cause a preexec for $PROMPT_COMMAND
echo -ne "\033[$(( COLUMNS-15 ))C$(date +'%m%d-%H:%M:%S')\r"
}
trap 'preexec' DEBUG
fi
The `echo -ne ...` is what prints the date (month+day+time, year is assumed obvious) close to the right margin (COLUMNS-15), then prints `\r` to get back to left margin. This has pros (less space taken) and cons (shows up in copy&paste), you can surely edit the format to your liking if you prefer.
I'll have to check how the OP's PS0 compares with that however, maybe it can make my snippet even simpler? edit: Ah, IIUC, PS0 seems bash 4.4+, for better or worse: https://github.com/rcaloras/bash-preexec/issues/28 https://github.com/rcaloras/bash-preexec/issues/28