Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to dim specific exit codes #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions pureline
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,31 @@ function prompt_module {
# append to prompt: append a '$' prompt with optional return code for previous command
# arg: $1 foreground color
# arg; $2 background color
# PL_RETURN_CODE_DIMMED: change color for selected exit codes.
# Define it like '130' or '14|153|..'. Value with pipe must be in quotes
# PL_RETURN_CODE_DIMMED_BG: color
# PL_RETURN_CODE_DIMMED_FG: color
function return_code_module {
if [ ! "$__return_code" -eq 0 ]; then
local bg_color="$1"
local fg_color="$2"
local content=" ${PL_SYMBOLS[return_code]} $__return_code "
PS1+="$(section_end $fg_color $bg_color)"
PS1+="$(section_content $fg_color $bg_color "$content")"
__last_color="$bg_color"
fi
[ "$__return_code" -eq 0 ] && return 0

local initial_state_extglob=$(shopt -p extglob)
shopt -s extglob
local regex="@(${PL_RETURN_CODE_DIMMED:-0})"
case "$__return_code" in
$regex)
local bg_color="${PL_RETURN_CODE_DIMMED_BG:-$1}"
local fg_color="${PL_RETURN_CODE_DIMMED_FG:-$2}"
;;
*)
local bg_color="$1"
local fg_color="$2"
;;
esac
$initial_state_extglob
local content=" ${PL_SYMBOLS[return_code]} $__return_code "
PS1+="$(section_end $fg_color $bg_color)"
PS1+="$(section_content $fg_color $bg_color "$content")"
__last_color="$bg_color"
}

# -----------------------------------------------------------------------------
Expand Down