Unverified Commit 4a9169ee authored by Mark Vander Stel's avatar Mark Vander Stel
Browse files

Fix multicommand command line not setting runtime

Since Liquidprompt uses the DEBUG trap to calculate runtime of commands,
we run into issue when the command line is actually multiple commands.
Bash runs the DEBUG trap before each command, not each command line,
which was making our time calculations not work at all.

Using a hack inspired by this post:
https://jichu4n.com/posts/debug-trap-and-prompt_command-in-bash/
We set a flag _LP_AT_PROMPT var when we are running PROMPT_COMMAND, and
only then in the DEBUG trap do we start the timer.

Fixes #614
parent 94148e54
......@@ -37,6 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **root**: `$LP_MARK_DEFAULT` being ignored if root ([#501], [5ee3c53])
- **runtime**: when runtime enabled, `$_` would evaluate as
`_lp_runtime_before` ([#451])
- **runtime**: when running a multipart command line (with pipes or `;`),
runtime would never show. Now shows runtime of whole pipeline ([#614])
- **tmux**: tmux not showing as multiplexer if custom `$TERM` set ([#563])
### Changed
......@@ -311,6 +313,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#604]: https://github.com/nojhan/liquidprompt/pull/604
[#605]: https://github.com/nojhan/liquidprompt/pull/605
[#613]: https://github.com/nojhan/liquidprompt/issues/613
[#614]: https://github.com/nojhan/liquidprompt/issues/614
[0234a58]: https://github.com/nojhan/liquidprompt/commit/0234a581d023fb6c40e5339f6dcbd619a33b4553
[02bc49e]: https://github.com/nojhan/liquidprompt/commit/02bc49edf306749c47d7a389dc916cb68e992cc8
......
......@@ -188,3 +188,4 @@ Thanks again to everyone for all of the help and support!
* Daniel Pinyol (@dpinol)
* Alyssa Ross (@alyssais)
* Gergo Szonyi (@gex)
* Nolan Leake (@nolanl)
......@@ -1429,22 +1429,19 @@ if (( LP_ENABLE_RUNTIME || LP_ENABLE_RUNTIME_BELL)); then
# If the previous command was just the refresh of the prompt,
# reset the counter
if (( _LP_RUNTIME_SKIP )); then
_LP_RUNTIME_SECONDS=-1 _LP_RUNTIME_LAST_SECONDS=$SECONDS
else
if (( _LP_AT_PROMPT )); then
_LP_RUNTIME_SECONDS=-1 _LP_RUNTIME_LAST_SECONDS=$SECONDS _LP_AT_PROMPT=0
elif [[ "$BASH_COMMAND" == "$PROMPT_COMMAND" ]]; then
_LP_AT_PROMPT=1
# Compute number of seconds since program was started
if [[ -n "$_LP_RUNTIME_LAST_SECONDS" ]] ; then
if [[ -n "${_LP_RUNTIME_LAST_SECONDS-}" ]] ; then
(( _LP_RUNTIME_SECONDS=SECONDS-_LP_RUNTIME_LAST_SECONDS ))
unset _LP_RUNTIME_LAST_SECONDS
fi
fi
# If the command to run is the prompt, we'll have to ignore it
[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]]
_LP_RUNTIME_SKIP=$?
}
_LP_RUNTIME_SKIP=0
_LP_AT_PROMPT=0
# _lp_runtime_before gets called just before bash executes a command,
# including $PROMPT_COMMAND
# Pass $_ to this call, because it sets $_ to what it already was
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment