Prompt command times

Moki Lv6

Dates before and after execution

Show date before execution:

1
PS0=">>> \$(date +%Y-%m-%d\ %T.%3N)\\n$PS0"

Show date after execution:

1
PROMPT_COMMAND='echo "<<< $(date +%Y-%m-%d\ %T.%3N)";'$PROMPT_COMMAND

Execution time

1
2
3
PS0='${t:0:$((t=$(date +%s%N),0))}'
PROMPT_COMMAND='(( t )) && printf "Seconds: %d.%09ds, Status: $?\\n" $((t=$(date +%s%N)-t,t/1000000000)) $((t%1000000000)) ; t=0'
sleep 0.1

Both

1
2
PS0="\e[33m>>> \$(date +%Y-%m-%d\ %T.%3N)\e[0m\\n\${t:0:\$((t=\$(date +%s%N),0))}"
PROMPT_COMMAND='(( t )) && ( echo -ne "\e[33m<<< $(date +%Y-%m-%d\ %T.%3N)" ; printf ", Seconds: %d.%09ds, Status: $?\\n" $((t=$(date +%s%N)-t,t/1000000000)) $((t%1000000000)) ; echo -en "\e[0m" ) ; t=0 ; '$PROMPT_COMMAND