bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] prompt: add \m, PROMPTTIMEFORMAT, shopt prompt_time_all


From: Koichi Murase
Subject: Re: [PATCH] prompt: add \m, PROMPTTIMEFORMAT, shopt prompt_time_all
Date: Wed, 27 Nov 2024 12:05:12 +0900

Isn't this achievable with PS0 and Bash-5.3 valsub?

_prompt_time() {
  if [[ $_prompt_time_start ]]; then
    _prompt_time=$((${EPOCHREALTIME//[!0-9]}-_prompt_time_start))
    _prompt_time_start=
  fi
  printf -v REPLY '%d.%06d' "$((_prompt_time/1000000))"
"$((_prompt_time%1000000))"
}
PS0+='${| _prompt_time_start=${EPOCHREALTIME//[!0-9]}; }'
PS1='${| _prompt_time; }\$ '

If you want the CPU times for sys/usr, you can call the `times'
builtin instead of referencing EPOCHREALTIME. If you want to exclude
the time of PROMPT_COMMAND, you can update the variable `_prompt_time'
at the beginning of `PROMPT_COMMAND[0]'.

--
Koichi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]