From 08034067d008ea894e56a587da23b5f38425b0c9 Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Thu, 2 Jan 2025 17:03:00 -0600 Subject: [PATCH] bash: Fix 50-prompt.sh to work with zsh as well as bash Also fix method of getting shell to get current, not default **Summary** --- packages/b/bash/files/profile/50-prompt.sh | 41 ++++++++++++++++++---- packages/b/bash/pspec_x86_64.xml | 2 +- packages/z/zsh/package.yml | 3 ++ packages/z/zsh/pspec_x86_64.xml | 3 +- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/packages/b/bash/files/profile/50-prompt.sh b/packages/b/bash/files/profile/50-prompt.sh index bbc64404ca0..b27812463d0 100644 --- a/packages/b/bash/files/profile/50-prompt.sh +++ b/packages/b/bash/files/profile/50-prompt.sh @@ -1,24 +1,53 @@ # Begin /usr/share/defaults/etc/profile.d/50-prompt.sh +# We cant use $SHELL since we need the *current* shell. +# The user may switch to a different shell than their default +# e.g. $SHELL is zsh but user switches to bash temporarily + +current_shell=$(readlink /proc/$$/exe) + endchar="\$" if [ "$UID" = "0" ]; then endchar="#" +elif [[ "$current_shell" =~ zsh ]]; then + endchar='%' fi -FG="\[\033[38;5;081m\]" -BG="\[\033[38;5;245m\]" -AT="\[\033[38;5;245m\]" -HCOLOR="\[\033[38;5;206m\]" +# Prefer tput to ANSI codes since they work with bash and zsh +# and are much easier to read +grey=$(tput setaf 245) +pink=$(tput setaf 206) +cyan=$(tput setaf 81) +reset_color=$(tput sgr0) -PS1="${FG}\u${AT}@${HCOLOR}\H ${BG}\w ${FG}$endchar \[\e[0m\]" +FG=$cyan +DIR=$grey +AT=$grey +HCOLOR=$pink + +# bash and zsh handle prompt setup and character escaping differently + +if [[ "$current_shell" =~ bash ]]; then + PS1="\[${FG}\]\u\[${AT}\]@\[${HCOLOR}\]\H \[${DIR}\]\w \[${FG}\]$endchar \[${reset_color}\]" +elif [[ "$current_shell" =~ zsh ]]; then + PS1="%{${FG}%}%n%{${AT}%}@%{${HCOLOR}%}%m %{${DIR}%}%1~ %{${FG}%}$endchar# ${reset_color}" +fi unset FG unset BG unset AT unset HCOLOR +unset grey +unset pink +unset cyan +unset reset_color +unset endchar + # shopt is bash only -if [ $SHELL = "/usr/bin/bash" ]; then +if [[ "$current_shell" =~ bash ]]; then shopt -s checkwinsize fi +unset current_shell + # End /usr/share/defaults/etc/profile.d/50-prompt.sh diff --git a/packages/b/bash/pspec_x86_64.xml b/packages/b/bash/pspec_x86_64.xml index f0e8698eae6..85de4a7d824 100644 --- a/packages/b/bash/pspec_x86_64.xml +++ b/packages/b/bash/pspec_x86_64.xml @@ -202,7 +202,7 @@ - 2024-11-12 + 2025-01-03 5.2.37 Packaging update Tracey Clark diff --git a/packages/z/zsh/package.yml b/packages/z/zsh/package.yml index 66debcf9a45..829e93d8a16 100644 --- a/packages/z/zsh/package.yml +++ b/packages/z/zsh/package.yml @@ -46,6 +46,9 @@ install : | ln -srv $installdir/usr/bin/$FILE $installdir/bin/$FILE done popd + + # Install defaults to /etc/skel + install -Dm0644 -t $installdir/etc/skel $pkgfiles/skel/.zshrc check : | unset LD_PRELOAD %make check diff --git a/packages/z/zsh/pspec_x86_64.xml b/packages/z/zsh/pspec_x86_64.xml index cc7d0b16329..5149bc07bf9 100644 --- a/packages/z/zsh/pspec_x86_64.xml +++ b/packages/z/zsh/pspec_x86_64.xml @@ -22,6 +22,7 @@ /bin/zsh /bin/zsh-5.9 + /etc/skel/.zshrc /usr/bin/zsh /usr/bin/zsh-5.9 /usr/lib64/zsh/5.9/zsh/attr.so @@ -1398,7 +1399,7 @@ - 2024-11-12 + 2025-01-01 5.9 Packaging update Tracey Clark