From 96c032f92783af8cbffd14014d4fe63f79199b03 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sun, 19 Nov 2023 13:21:08 +0100 Subject: bashrc: refactor prompt setting into PROMPT_COMMAND --- bashrc | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) (limited to 'bashrc') diff --git a/bashrc b/bashrc index 8582ad0..916ad2b 100644 --- a/bashrc +++ b/bashrc @@ -48,17 +48,42 @@ case "$TERM" in esac # prompt -reset='\[\033[0m\]' -yellow_b='\[\033[1;33m\]' -green='\[\033[0;32m\]' -red='\[\033[0;31m\]' -red_b='\[\033[1;31m\]' -[ $(id -u) -eq 0 ] && user_color=$red_b || user_color=$yellow_b -nrjobs='$([ \j -gt 0 ] && echo " [\j]")' -gitps='$(type -t __git_ps1 &>/dev/null && __git_ps1)' -[ -n "$debian_chroot" ] && chroot="[$debian_chroot] " -[ -n "$container" ] && container="[$container] " -PS1=${TITLE}"($user_color\u$reset@$green\h$reset) $container$chroot\W$gitps$nrjobs $red\\\$$reset > " +__prompt_command() { + PS1='${TITLE}' + + local reset='\[\033[0m\]' + local yellow_b='\[\033[1;33m\]' + local green='\[\033[0;32m\]' + local red='\[\033[0;31m\]' + local red_b='\[\033[1;31m\]' + + # user name + [ $(id -u) -eq 0 ] && local user_color=$red_b || local user_color=$yellow_b + PS1+="($user_color\u$reset@$green\h$reset)" + + # chroot / container + if [ -n "$container" ]; then + PS1+=" [$container]" + fi + if [ -n "$debian_chroot" ]; then + PS1+=" [$debian_chroot]" + fi + + # directory base + PS1+=" \W" + + # git + local gitps='$(type -t __git_ps1 &>/dev/null && __git_ps1)' + PS1+="$gitps" + + # background jobs + if [ -n "$(jobs -p)" ]; then + PS1+=" [\j]" + fi + + PS1+=" $red\$$reset > " +} +PROMPT_COMMAND=__prompt_command # history HISTCONTROL='ignoredups:erasedups' -- cgit v1.2.3