Skip to content

Commit

Permalink
bash: Fix 50-prompt.sh to work with zsh as well as bash
Browse files Browse the repository at this point in the history
Also fix method of getting shell to get current, not default

**Summary**
  • Loading branch information
TraceyC77 committed Jan 3, 2025
1 parent e435571 commit 0803406
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
41 changes: 35 additions & 6 deletions packages/b/bash/files/profile/50-prompt.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/b/bash/pspec_x86_64.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
</Package>
<History>
<Update release="85">
<Date>2024-11-12</Date>
<Date>2025-01-03</Date>
<Version>5.2.37</Version>
<Comment>Packaging update</Comment>
<Name>Tracey Clark</Name>
Expand Down
3 changes: 3 additions & 0 deletions packages/z/zsh/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion packages/z/zsh/pspec_x86_64.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<Files>
<Path fileType="executable">/bin/zsh</Path>
<Path fileType="executable">/bin/zsh-5.9</Path>
<Path fileType="config">/etc/skel/.zshrc</Path>
<Path fileType="executable">/usr/bin/zsh</Path>
<Path fileType="executable">/usr/bin/zsh-5.9</Path>
<Path fileType="library">/usr/lib64/zsh/5.9/zsh/attr.so</Path>
Expand Down Expand Up @@ -1398,7 +1399,7 @@
</Package>
<History>
<Update release="35">
<Date>2024-11-12</Date>
<Date>2025-01-01</Date>
<Version>5.9</Version>
<Comment>Packaging update</Comment>
<Name>Tracey Clark</Name>
Expand Down

0 comments on commit 0803406

Please sign in to comment.