Skip to content

Commit

Permalink
Save bell sequence to var to save time on bell
Browse files Browse the repository at this point in the history
We do all our other 'tput' calls in _lp_source_config() to save time
while running, so why not do the bell as well.
Also move the bell check out of the runtime function, since it's
something that isn't actually tied to the runtime enabled config.
  • Loading branch information
Rycieos committed Nov 25, 2020
1 parent 3f57231 commit 3e615cd
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ _lp_source_config() {

local ti_sgr0="$( { tput sgr0 || tput me ; } 2>/dev/null )"
local ti_bold="$( { tput bold || tput md ; } 2>/dev/null )"
_LP_TI_BELL="$( { tput bel || tput bl ; } 2>/dev/null )"
if tput setaf 0 >/dev/null 2>&1; then
foreground_color() { af_color="${af_colors[$1+1]:=$(tput setaf $1)}"; }
elif tput AF 0 >/dev/null 2>&1; then
Expand Down Expand Up @@ -1499,12 +1500,6 @@ _lp_runtime() {
(( _LP_RUNTIME_SECONDS >= 60 )) && echo -n $((_LP_RUNTIME_SECONDS % 3600 / 60))m
echo -n $((_LP_RUNTIME_SECONDS % 60))"s${NO_COL}"
fi
if (( LP_ENABLE_RUNTIME_BELL && _LP_RUNTIME_SECONDS >= LP_RUNTIME_BELL_THRESHOLD ))
then
#bash reprints $PS1 on every SIGWINCH, so we tput to stderr here so the bell is not
#captured in PS1. This way the bell only rings once, not on every terminal resize.
{ tput bel || tput bl ; } >&2 2>/dev/null
fi
:
}

Expand Down Expand Up @@ -1874,6 +1869,10 @@ _lp_set_prompt() {
# bash: execute the old prompt hook
eval "$LP_OLD_PROMPT_COMMAND"

if (( LP_ENABLE_RUNTIME_BELL && _LP_RUNTIME_SECONDS >= LP_RUNTIME_BELL_THRESHOLD )); then
printf '%s' "$_LP_TI_BELL"
fi

# if change of working directory
if [[ "${LP_OLD_PWD-}" != "LP:$PWD" ]]; then
# Update directory icon for MacOS X
Expand Down

0 comments on commit 3e615cd

Please sign in to comment.