Modify our hostname get in the Bash PS1 to work on systems without hostname installed

Might just switch to that permanently tbh; it's nicer and quicker
This commit is contained in:
Salt 2022-04-13 18:53:44 -05:00
parent 149c957d37
commit ae733d53b3

View File

@ -328,9 +328,15 @@ _ps1bash() {
# Add hostname prefix in SSH sessions
unset _prefix
# Get the system hostname, using a util if one's available
if command -v hostname; then
_hostname="$(hostname -s)"
else
_hostname="$(</etc/hostname)"
fi
# Alert if in an SSH session
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
_prefix="${fg_bold}${fg_red}$(hostname -s)${r}${fg_red}:${r}${_prefix}"
_prefix="${fg_bold}${fg_red}${_hostname}${r}${fg_red}:${r}${_prefix}"
elif [ "$USER" != "salt" ]; then
_prefix="${fg_bold}${fg_yellow}$USER${r}${fg_yellow}:${r}${_prefix}"
fi