From abcc68b2f72081b435afac82ce5760d416ac7b87 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 15 Sep 2015 16:21:47 +0200 Subject: [PATCH 1/3] Added NoExitState version of my TruncatedPwd theme --- ...ncatedPwd_WindowTitle_NoExitState.bgptheme | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme diff --git a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme new file mode 100644 index 0000000..09f1ba9 --- /dev/null +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -0,0 +1,54 @@ +############################################################################## +# Changes the prompt to a Debian-style one that truncates pwd to a max length +# depending on the terminal column width. Also uses the prompt_callback +# function of bash-git-prompt to set the window title to almost the same +# Debian-style. +# +# The prompt will use a Debian-style on the form +# +# [user@host: ] [bash-git-prompt-info] +# HH:MM $ +# +# The window title will have the form +# user@host: +# +# Example usage: +# if [ -f ~/.bash-git-prompt/gitprompt.sh ]; then +# GIT_PROMPT_THEME=TruncatedPwd_WindowTitle +# source ~/.bash-git-prompt/gitprompt.sh +# fi +# +# oGre [https://github.com/ogr3] +############################################################################## +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle" + + #Sets the window title to the given argument string + function gp_set_title { + echo -ne "\033]0;"$@"\007" + } + + #Helper function that truncates $PWD depending on window width + function gp_truncate_pwd { + local newPWD="${PWD/#$HOME/~}" + local pwdmaxlen=$((${COLUMNS:-80}/3)) + [ ${#newPWD} -gt $pwdmaxlen ] && newPWD="...${newPWD:3-$pwdmaxlen}" + echo -n "$newPWD" + } + + #Overrides the prompt_callback function used by bash-git-prompt + function prompt_callback { + local PS1="\u@\h: $(gp_truncate_pwd)" + gp_set_title $PS1 + echo -n "[${PS1}]${ResetColor}" + } + + Time12a="\$(date +%H:%M)" + + GIT_PROMPT_START_USER="${Yellow}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER="\n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT="\n${White}${Time12a}${ResetColor} # " +} + +reload_git_prompt_colors "TruncatedPwd_WindowTitle" From 168d33c3ab5ae0ad794e0771d1c6376b12360518 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 15 Sep 2015 16:24:43 +0200 Subject: [PATCH 2/3] Fixed name everywhere and documentation --- themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme index 09f1ba9..f0bb330 100644 --- a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -6,7 +6,7 @@ # # The prompt will use a Debian-style on the form # -# [user@host: ] [bash-git-prompt-info] +# [user@host: ] [bash-git-prompt-info] # HH:MM $ # # The window title will have the form @@ -14,14 +14,14 @@ # # Example usage: # if [ -f ~/.bash-git-prompt/gitprompt.sh ]; then -# GIT_PROMPT_THEME=TruncatedPwd_WindowTitle +# GIT_PROMPT_THEME=TruncatedPwd_WindowTitle_NoExitState # source ~/.bash-git-prompt/gitprompt.sh # fi # # oGre [https://github.com/ogr3] ############################################################################## override_git_prompt_colors() { - GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle" + GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle_NoExitState" #Sets the window title to the given argument string function gp_set_title { @@ -51,4 +51,4 @@ override_git_prompt_colors() { GIT_PROMPT_END_ROOT="\n${White}${Time12a}${ResetColor} # " } -reload_git_prompt_colors "TruncatedPwd_WindowTitle" +reload_git_prompt_colors "TruncatedPwd_WindowTitle_NoExitState" From ee959b7e5921d969f1613c6889c5bbb39a1aae50 Mon Sep 17 00:00:00 2001 From: oGre Date: Wed, 16 Sep 2015 06:20:02 +0200 Subject: [PATCH 3/3] Remove training whitespace --- themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme index f0bb330..fdd0f50 100644 --- a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -1,13 +1,13 @@ ############################################################################## # Changes the prompt to a Debian-style one that truncates pwd to a max length -# depending on the terminal column width. Also uses the prompt_callback -# function of bash-git-prompt to set the window title to almost the same +# depending on the terminal column width. Also uses the prompt_callback +# function of bash-git-prompt to set the window title to almost the same # Debian-style. # # The prompt will use a Debian-style on the form # -# [user@host: ] [bash-git-prompt-info] -# HH:MM $ +# [user@host: ] [bash-git-prompt-info] +# HH:MM $ # # The window title will have the form # user@host: @@ -44,7 +44,7 @@ override_git_prompt_colors() { } Time12a="\$(date +%H:%M)" - + GIT_PROMPT_START_USER="${Yellow}" GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" GIT_PROMPT_END_USER="\n${White}${Time12a}${ResetColor} $ "