From e351f2e9240881eab6904e1077efa6d7dcb238ef Mon Sep 17 00:00:00 2001 From: lachtan Date: Thu, 12 Mar 2026 12:35:41 +0100 Subject: [PATCH] Extract shared prompt values and refactor bash/git prompts Move color constants and PS1 escape sequences from bash-prompt.sh into a new shared rc/03-values.sh, and extract the user@host:dir fragment as LWS_PS1_USER_HOST to eliminate duplication between bash-prompt.sh and git-prompt.sh. Wire up git-prompt to use bash-git-prompt with the shared prompt variables. --- rc/03-values.sh | 12 ++++++++++++ rc/bash-prompt.sh | 12 +----------- rc/git-prompt.sh | 3 +++ 3 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 rc/03-values.sh diff --git a/rc/03-values.sh b/rc/03-values.sh new file mode 100644 index 0000000..8d126c3 --- /dev/null +++ b/rc/03-values.sh @@ -0,0 +1,12 @@ +# Terminal colors +LWS_RED=$(tput setaf 1) +LWS_GREEN=$(tput setaf 2) +LWS_CYAN=$(tput setaf 6) +LWS_COLOR_RESET=$(tput sgr0) + +# Bash prompt escape sequences +LWS_PS1_USER='\u' +LWS_PS1_HOST='\h' +LWS_PS1_DIR='\w' +LWS_PS1_TYPE='\$' +LWS_PS1_USER_HOST="${LWS_GREEN}${LWS_PS1_USER}@${LWS_PS1_HOST}${LWS_COLOR_RESET}:${LWS_CYAN}${LWS_PS1_DIR}${LWS_COLOR_RESET}" diff --git a/rc/bash-prompt.sh b/rc/bash-prompt.sh index 15bccd7..7dafb81 100644 --- a/rc/bash-prompt.sh +++ b/rc/bash-prompt.sh @@ -2,19 +2,9 @@ # https://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/ # https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/ -RED=$(tput setaf 1) -GREEN=$(tput setaf 2) -CYAN=$(tput setaf 6) -COLOR_RESET=$(tput sgr0) - function get_ps1_prompt() { - local username='\u' - local hostname='\h' - local workdir='\w' - local user_type='\$' - - echo "${debian_chroot:+($debian_chroot)}${GREEN}${username}@${hostname}${COLOR_RESET}:${CYAN}${workdir}${COLOR_RESET}${user_type} " + echo "${debian_chroot:+($debian_chroot)}${LWS_PS1_USER_HOST}${LWS_PS1_TYPE} " } function set_ps1_prompt() diff --git a/rc/git-prompt.sh b/rc/git-prompt.sh index b972b1c..f021731 100644 --- a/rc/git-prompt.sh +++ b/rc/git-prompt.sh @@ -9,5 +9,8 @@ GIT_PROMPT_INIT="$GIT_PROMPT_PATH/gitprompt.sh" if [ -f "$GIT_PROMPT_INIT" ]; then export GIT_PROMPT_PATH GIT_PROMPT_ONLY_IN_REPO=1 + GIT_PROMPT_USER_HOST="${LWS_PS1_USER_HOST}" + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_USER_HOST}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" source "$GIT_PROMPT_INIT" fi