From b5af1ebd3bcef4fefac5a0b2efa1b9c5f7d253bd Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Tue, 2 Mar 2021 20:37:31 +0100 Subject: [PATCH] feat(bash): execution time --- src/init/omp.bash | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/init/omp.bash b/src/init/omp.bash index 6329e7e4..5fa20519 100644 --- a/src/init/omp.bash +++ b/src/init/omp.bash @@ -1,9 +1,26 @@ export POSH_THEME=::CONFIG:: +TIMER_START="/tmp/${USER}.start.$$" + +PS0='$(::OMP:: --millis > $TIMER_START)' + function _update_ps1() { - PS1="$(::OMP:: --config $POSH_THEME --error $?)" + omp_elapsed=-1 + if [[ -f $TIMER_START ]]; then + omp_now=$(::OMP:: --millis) + omp_start_time=$(cat "$TIMER_START") + omp_elapsed=$(($omp_now-$omp_start_time)) + rm $TIMER_START + fi + PS1="$(::OMP:: --config $POSH_THEME --error $? --execution-time $omp_elapsed)" } if [ "$TERM" != "linux" ] && [ -x "$(command -v ::OMP::)" ]; then PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND" fi + +function runonexit() { + rm $TIMER_START +} + +trap runonexit EXIT