From 71ec4e32028745af05c533d5a4d4b4dc687b4505 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Mon, 7 Nov 2016 19:14:21 +0100 Subject: Add "automatic" setting for hostname display This will show the hostname when logged in over SSH. --- .bashprompt | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/.bashprompt b/.bashprompt index 49869fb..5fd4d01 100644 --- 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 -- cgit v1.2.3