commit 71ec4e32028745af05c533d5a4d4b4dc687b4505 parent ee4a279a639b9a3c543c0a72583a03a4395302b0 Author: KΓ©vin Le Gouguec <kevin.legouguec@gmail.com> Date: Mon, 7 Nov 2016 19:14:21 +0100 Add "automatic" setting for hostname display This will show the hostname when logged in over SSH. Diffstat:
| M | .bashprompt | | | 38 | +++++++++++++++++++++++++++++++++----- |
1 file changed, 33 insertions(+), 5 deletions(-)
diff --git a/.bashprompt b/.bashprompt @@ -1,13 +1,41 @@ +# Environment variables: +# +# PS1_SHOWHOSTNAME +# 'auto' (default): Only show hostname over SSH +# 'yes': Always show hostname +# anything else: Never show hostname + + +__show-hostname () +{ + case "${PS1_SHOWHOSTNAME}" in + (''|auto) + [ "${SSH_CONNECTION}" ] + return $?;; + (yes) + return 0;; + (*) + return 1;; + esac +} + __set-title () { local title - local path=$(git root 2> /dev/null) + local git_root=$(git root 2> /dev/null) - if [ ${path} ] + if [ ${git_root} ] then - title=$(basename ${path}) + title=$(basename ${git_root}) else - title="${USER}:${PWD/~/\~}" + local path=${PWD/~/\~} + + if __show-hostname + then + title="${USER}@${HOSTNAME}:${path}" + else + title="${USER}:${path}" + fi fi echo -ne "\033]2;${title}\007" @@ -85,7 +113,7 @@ __set-prompt () PS1+=$(__fontify '\u' green) - if [ ${PS1_SHOWHOSTNAME} ] + if __show-hostname then PS1+=$(__fontify '@\H' dim green) fi