shell-color-prompt/bash-color-prompt.sh
2023-08-21 23:42:22 +08:00

21 lines
864 B
Bash

## to shorten \w dirpath:
# PROMPT_DIRTRIM=4
# See <https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters> for ANSI codes
# only set for color terminals and if PS1 unchanged
if [ "$PS1" = "[\u@\h \W]\\$ " -a "${TERM: -5}" = "color" -o -n "${prompt_color_force}" ]; then
# examples:
# PROMPT_COLOR=0 # disable colors/attribs
# PROMPT_COLOR=1 # bold prompt
# PROMPT_COLOR=2 # dim prompt
# PROMPT_COLOR=4 # underline prompt
# PROMPT_COLOR='2;7' # dim reverse video
# PROMPT_COLOR='42' # green background
# PROMPT_COLOR='53' # overline separator
# PROMPT_COLOR='1;33;44' # bold yellow on blue
# PROMPT_COLOR='1;32' # bold green
# PROMPT_COLOR='' # unset defaults to green
PS1='\[\e[${PROMPT_COLOR:-32}m\]\u@\h\[\e[0m\]:\[\e[${PROMPT_COLOR:-32}m\]\w\[\e[0;31m\]${?#0}\[\e[0m\]\$ '
fi