From 81ed607e3275cef9cd4d18c8aa9e1c025bbaefbe Mon Sep 17 00:00:00 2001 From: Jens Petersen Date: Mon, 13 Nov 2023 12:30:32 +0800 Subject: [PATCH] only define default functions if setting PS1 --- bash-color-prompt.sh | 56 ++++++++++++++++++++--------------------- shell-color-prompt.spec | 5 +++- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/bash-color-prompt.sh b/bash-color-prompt.sh index d817ed8..fc230f1 100644 --- a/bash-color-prompt.sh +++ b/bash-color-prompt.sh @@ -10,32 +10,32 @@ if [ '(' "$PS1" = "[\u@\h \W]\\$ " -o "$PS1" = "\\s-\\v\\\$ " ')' -a "${TERM: -5 PROMPT_DIRECTORY='\w' 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}\$ ' + 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='' + } + 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 bba3ed4..1ac1c2e 100644 --- a/shell-color-prompt.spec +++ b/shell-color-prompt.spec @@ -1,6 +1,6 @@ Name: shell-color-prompt Version: 0.3 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Color prompt for bash shell License: GPL-2.0-or-later @@ -41,6 +41,9 @@ install -m 644 -D -t %{buildroot}%{profiledir} bash-color-prompt.sh %changelog +* Mon Nov 13 2023 Jens Petersen - 0.3-2 +- only define default functions if setting PS1 + * 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)