diff --git a/README.md b/README.md index ff498c8..fd082e8 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,13 @@ PROMPT_DIRECTORY='\W' PROMPT_COLOR='0' ``` +## Defaults functions +The traditional Red Hat prompt can be set with the `prompt_traditional` function. + +The prompt can be reset to default with the `prompt_default` function. + +Use the `prompt_default_os` function to use `ANSI_COLOR` from `/etc/os-release`. + ## Sourcing Set `prompt_color_force` (before source'ing) to force usage/updating of color PS1: by default it is only setup cautiously if `$TERM` ends in "color" @@ -78,3 +85,5 @@ $ source /etc/profile.d/bash-color-prompt.sh ## Contribute Please open issues against [shell-color-prompt](https://src.fedoraproject.org/rpms/shell-color-prompt). + +shell-color is distributed under the GPL license version 2 or later. diff --git a/bash-color-prompt.sh b/bash-color-prompt.sh index 8bf79fc..d817ed8 100644 --- a/bash-color-prompt.sh +++ b/bash-color-prompt.sh @@ -11,3 +11,31 @@ if [ '(' "$PS1" = "[\u@\h \W]\\$ " -o "$PS1" = "\\s-\\v\\\$ " ')' -a "${TERM: -5 PS1='${PROMPT_START@P}\[\e[${PROMPT_COLOR:-32}m\]${container:+⬢ }\u@\h\[\e[0m\]${PROMPT_SEPARATOR@P}\[\e[${PROMPT_DIR_COLOR:-${PROMPT_COLOR:-32}}m\]${PROMPT_DIRECTORY@P}${PROMPT_ERROR:+\[\e[0;31m\]${?#0}}\[\e[0m\]${PROMPT_END@P}\$ ' fi + +prompt_default() { + PROMPT_COLOR="$1" + PROMPT_DIR_COLOR="$2" + PROMPT_SEPARATOR=':' + PROMPT_DIRECTORY='\w' + PROMPT_START='' + PROMPT_END='' +} + +prompt_traditional() { + PROMPT_COLOR="${1:-0}" + PROMPT_DIR_COLOR="${2}" + PROMPT_SEPARATOR=' ' + PROMPT_DIRECTORY='\W' + PROMPT_START='[' + PROMPT_END=']' +} + +prompt_default_os() { + eval $(grep ANSI_COLOR /etc/os-release) + PROMPT_COLOR="$ANSI_COLOR" + PROMPT_DIR_COLOR="$1" + PROMPT_SEPARATOR=':' + PROMPT_DIRECTORY='\w' + PROMPT_START='' + PROMPT_END='' +} diff --git a/shell-color-prompt.spec b/shell-color-prompt.spec index 61f3dda..bba3ed4 100644 --- a/shell-color-prompt.spec +++ b/shell-color-prompt.spec @@ -44,6 +44,7 @@ install -m 644 -D -t %{buildroot}%{profiledir} bash-color-prompt.sh * Mon Nov 13 2023 Jens Petersen - 0.3-1 - add PROMPT_SEPARATOR and PROMPT_DIRECTORY default variables (#2239152) - add optional PROMPT_START and PROMPT_END (replaces PROMPT_BRACKETS) +- add prompt_default(), prompt_traditional(), and prompt_default_os() - expand README.md * Sat Nov 11 2023 Jens Petersen - 0.2.1-1