-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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**
- Loading branch information
Showing
4 changed files
with
41 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters