diff --git a/gitprompt.sh b/gitprompt.sh index 4a5f30a..5f3a4fe 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -521,6 +521,19 @@ function is_function { declare -Ff "$1" >/dev/null; } +#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" +} + +#Sets the window title to the given argument string +function gp_set_window_title { + echo -ne "\033]0;"$@"\007" +} + function prompt_callback_default { return } diff --git a/themes/TruncatedPwd_WindowTitle.bgptheme b/themes/TruncatedPwd_WindowTitle.bgptheme index 3c2c4cc..b7f94e2 100644 --- a/themes/TruncatedPwd_WindowTitle.bgptheme +++ b/themes/TruncatedPwd_WindowTitle.bgptheme @@ -23,23 +23,10 @@ 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 + gp_set_window_title "$PS1" echo -n "[${PS1}]${ResetColor}" } diff --git a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme index fdd0f50..6e63676 100644 --- a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -23,23 +23,10 @@ override_git_prompt_colors() { GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle_NoExitState" - #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 + gp_set_window_title "$PS1" echo -n "[${PS1}]${ResetColor}" }