Skip to content

Commit

Permalink
Avoid showing the 130 error code after hitting ^C
Browse files Browse the repository at this point in the history
When a user hits ^C on command line to cancel entering a lengthy
command, $! in __lp_set_prompt is set to 130 (128 + SIGINT). Displaying
this error on the input line (especially in warning colours) makes
little sense.  Therefore, liquidprompt should check if the command
submitted is a real command or is it part of PROMPT_COMMAND in which
case the error does not come from a user's command and should not be
presented.
  • Loading branch information
steelman authored and Rycieos committed Apr 3, 2024
1 parent 436b1b5 commit 1be449e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions liquidprompt
Expand Up @@ -486,6 +486,7 @@ __lp_source_config() {
LP_ENABLE_OS_VERSION=${LP_ENABLE_OS_VERSION:-1}
LP_ENABLE_HYPERLINKS=${LP_ENABLE_HYPERLINKS:-0}
LP_ENABLE_PATH=${LP_ENABLE_PATH:-1}
LP_HIDE_EMPTY_ERROR=${LP_HIDE_EMPTY_ERROR:-1}

LP_MARK_DEFAULT="${LP_MARK_DEFAULT:-$_LP_MARK_SYMBOL}"
LP_MARK_BATTERY="${LP_MARK_BATTERY:-""}"
Expand Down Expand Up @@ -834,6 +835,7 @@ lp_activate() {
LP_ENABLE_RUNTIME \
|| LP_ENABLE_RUNTIME_BELL \
|| LP_ENABLE_TITLE_COMMAND \
|| LP_HIDE_EMPTY_ERROR \
))

# LP_ENABLE_RUBY_VENV depends either from rvm or rbenv. Thus we cannot
Expand Down Expand Up @@ -4810,6 +4812,11 @@ __lp_set_prompt() {
# As this get the last returned code, it should be called first
local -i lp_error="$?"

if (( LP_HIDE_EMPTY_ERROR )); then
(( ! ${_LP_REAL_COMMAND:-1} )) && lp_error=0
_LP_REAL_COMMAND=0
fi

if (( LP_ENABLE_RUNTIME || LP_ENABLE_RUNTIME_BELL )); then
__lp_runtime_after
fi
Expand Down Expand Up @@ -4858,6 +4865,9 @@ __lp_preexec() {
if (( LP_ENABLE_TITLE_COMMAND )); then
__lp_print_title_command
fi
if (( LP_HIDE_EMPTY_ERROR )); then
_LP_REAL_COMMAND=1
fi
}

__lp_before_command() {
Expand Down

0 comments on commit 1be449e

Please sign in to comment.