Skip to content

Commit

Permalink
Add LP_ENABLE_ERROR config option
Browse files Browse the repository at this point in the history
Add _lp_error() to get the last error, and to return a error code if
there is one. This is more to be in line with the other data functions.

Change lp_err to lp_error, to match the function name.
  • Loading branch information
Rycieos committed Dec 4, 2020
1 parent 5ef795d commit 63b9f73
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ prompt-building process:
* `LP_ENABLE_SUDO`, if you want the prompt mark to change color while you have password-less root access
* `LP_ENABLE_FQDN`, if you want the display of the fully qualified domain name
* `LP_ENABLE_TIME`, if you want to display the time at which the prompt was shown
* `LP_ENABLE_ERROR`, if you want to display the error code of the last command (if not 0)
* `LP_TIME_ANALOG`, if you want to show the time using an analog clock instead of numeric values

Note that if required commands are not installed, enabling the corresponding
Expand Down
27 changes: 20 additions & 7 deletions liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ __lp_source_config() {
LP_DISABLED_VCS_PATHS=("${LP_DISABLED_VCS_PATHS[@]-}")
LP_ENABLE_SUDO=${LP_ENABLE_SUDO:-0}
LP_ENABLE_COLOR=${LP_ENABLE_COLOR:-1}
LP_ENABLE_ERROR=${LP_ENABLE_ERROR:-1}

LP_MARK_DEFAULT="${LP_MARK_DEFAULT:-$_LP_MARK_SYMBOL}"
LP_MARK_BATTERY="${LP_MARK_BATTERY:-""}"
Expand Down Expand Up @@ -880,6 +881,18 @@ _lp_chroot() {
return 1
}

_lp_error() {
(( LP_ENABLE_ERROR )) || return 2

(( lp_error != 0 ))
}

_lp_error_color() {
_lp_error || return "$?"

lp_error_color="${LP_COLOR_ERR}${lp_error}${NO_COL}"
}

_lp_multiplexer() {
if [[ -n ${TMUX-} ]]; then
lp_mulitplexer=tmux
Expand Down Expand Up @@ -2508,12 +2521,6 @@ _lp_default_theme_directory() {
}

_lp_default_theme_prompt() {
if (( lp_err != 0 )); then
LP_ERR=" $LP_COLOR_ERR$lp_err$NO_COL"
else
LP_ERR=
fi

# left of main prompt: space at right
if _lp_jobcount_color; then
LP_JOBS="$lp_jobcount_color "
Expand Down Expand Up @@ -2569,6 +2576,12 @@ _lp_default_theme_prompt() {
LP_RUNTIME=
fi

if _lp_error_color; then
LP_ERR=" $lp_error_color"
else
LP_ERR=
fi

if _lp_find_vcs && _lp_vcs_details_color; then
LP_VCS=" $lp_vcs_details_color"
else
Expand Down Expand Up @@ -2617,7 +2630,7 @@ _lp_default_theme_prompt() {
__lp_set_prompt() {
# Display the return value of the last command, if different from zero
# As this get the last returned code, it should be called first
local -i lp_err=$?
local -i lp_error=$?

#TODO: unused?
local GREP_OPTIONS=
Expand Down
3 changes: 3 additions & 0 deletions liquidpromptrc-dist
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ LP_ENABLE_SCREEN_TITLE=0
# Use different colors for the different hosts you SSH to
LP_ENABLE_SSH_COLORS=0

# Show the error code of the last command if it was not 0
LP_ENABLE_ERROR=1

# Specify an array of absolute paths in which all vcs will be disabled.
# Ex: ("/root" "/home/me/large-remove-svn-repo")
LP_DISABLED_VCS_PATHS=()
Expand Down
4 changes: 2 additions & 2 deletions themes/powerline/powerline.theme
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ _lp_powerline_theme_prompt() {
fi
fi

if (( lp_err )); then
__powerline_section "${lp_err}" "${POWERLINE_ERROR_COLOR[@]}"
if _lp_error; then
__powerline_section "${lp_error}" "${POWERLINE_ERROR_COLOR[@]}"
fi

__powerline_end_terminator
Expand Down

0 comments on commit 63b9f73

Please sign in to comment.