Skip to content

Commit

Permalink
feat(bash): execution time
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Mar 3, 2021
1 parent 5bc4759 commit b5af1eb
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion 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

0 comments on commit b5af1eb

Please sign in to comment.