configs/home/.zsh/themes/spaceship-prompt/sections/char.zsh

47 lines
1.6 KiB
Bash
Raw Normal View History

2022-12-01 13:28:20 +01:00
#
# Prompt character
#
# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
SPACESHIP_CHAR_PREFIX="${SPACESHIP_CHAR_PREFIX=""}"
SPACESHIP_CHAR_SUFFIX="${SPACESHIP_CHAR_SUFFIX=""}"
SPACESHIP_CHAR_SYMBOL="${SPACESHIP_CHAR_SYMBOL="➜ "}"
SPACESHIP_CHAR_SYMBOL_ROOT="${SPACESHIP_CHAR_SYMBOL_ROOT="$SPACESHIP_CHAR_SYMBOL"}"
SPACESHIP_CHAR_SYMBOL_SUCCESS="${SPACESHIP_CHAR_SYMBOL_SUCCESS="$SPACESHIP_CHAR_SYMBOL"}"
SPACESHIP_CHAR_SYMBOL_FAILURE="${SPACESHIP_CHAR_SYMBOL_FAILURE="$SPACESHIP_CHAR_SYMBOL"}"
SPACESHIP_CHAR_SYMBOL_SECONDARY="${SPACESHIP_CHAR_SYMBOL_SECONDARY="$SPACESHIP_CHAR_SYMBOL"}"
SPACESHIP_CHAR_COLOR_SUCCESS="${SPACESHIP_CHAR_COLOR_SUCCESS="green"}"
SPACESHIP_CHAR_COLOR_FAILURE="${SPACESHIP_CHAR_COLOR_FAILURE="red"}"
SPACESHIP_CHAR_COLOR_SECONDARY="${SPACESHIP_CHAR_COLOR_SECONDARY="yellow"}"
# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------
# Paint $PROMPT_SYMBOL in red if previous command was fail and
# paint in green if everything was OK.
spaceship_char() {
local color char
if [[ $RETVAL -eq 0 ]]; then
color="$SPACESHIP_CHAR_COLOR_SUCCESS"
char="$SPACESHIP_CHAR_SYMBOL_SUCCESS"
else
color="$SPACESHIP_CHAR_COLOR_FAILURE"
char="$SPACESHIP_CHAR_SYMBOL_FAILURE"
fi
if [[ $UID -eq 0 ]]; then
char="$SPACESHIP_CHAR_SYMBOL_ROOT"
fi
spaceship::section \
--color "$color" \
--prefix "$SPACESHIP_CHAR_PREFIX" \
--suffix "$SPACESHIP_CHAR_SUFFIX" \
--symbol "$char"
}