From 1ba48fd06b9f15920a502d5e5698e5a188844335 Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 5 Oct 2015 18:27:13 +0200 Subject: [PATCH 1/3] Added helper function gp_set_window_title that can be used to set XTerm window title to the given argument. Used in TruncatedPwd_WindowTitle theme --- gitprompt.sh | 5 +++++ themes/TruncatedPwd_WindowTitle.bgptheme | 7 +------ themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme | 7 +------ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 00a79c2..65dc759 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -525,6 +525,11 @@ function is_function { declare -Ff "$1" >/dev/null; } +#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..29721c9 100644 --- a/themes/TruncatedPwd_WindowTitle.bgptheme +++ b/themes/TruncatedPwd_WindowTitle.bgptheme @@ -23,11 +23,6 @@ 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/~}" @@ -39,7 +34,7 @@ override_git_prompt_colors() { #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..9feca37 100644 --- a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -23,11 +23,6 @@ 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/~}" @@ -39,7 +34,7 @@ override_git_prompt_colors() { #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}" } From ff48c815879807be8ff8f9f7500bf1629ca8f757 Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 5 Oct 2015 18:29:04 +0200 Subject: [PATCH 2/3] Minor fix --- themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme index 9feca37..5a1bff1 100644 --- a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -34,7 +34,7 @@ override_git_prompt_colors() { #Overrides the prompt_callback function used by bash-git-prompt function prompt_callback { local PS1="\u@\h: $(gp_truncate_pwd)" - gp_set_window_title $PS1 + gp_set_window_title "$PS1" echo -n "[${PS1}]${ResetColor}" } From fbeaa6effd84f1f01df61d3f05efeb32b8901b53 Mon Sep 17 00:00:00 2001 From: oGre Date: Tue, 6 Oct 2015 08:55:18 +0200 Subject: [PATCH 3/3] Moved gp_truncate_pwd function to gitprompt.sh --- gitprompt.sh | 8 ++++++++ themes/TruncatedPwd_WindowTitle.bgptheme | 8 -------- themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme | 8 -------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 65dc759..e812a85 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -525,6 +525,14 @@ 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" diff --git a/themes/TruncatedPwd_WindowTitle.bgptheme b/themes/TruncatedPwd_WindowTitle.bgptheme index 29721c9..b7f94e2 100644 --- a/themes/TruncatedPwd_WindowTitle.bgptheme +++ b/themes/TruncatedPwd_WindowTitle.bgptheme @@ -23,14 +23,6 @@ override_git_prompt_colors() { GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle" - #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)" diff --git a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme index 5a1bff1..6e63676 100644 --- a/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme +++ b/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -23,14 +23,6 @@ override_git_prompt_colors() { GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle_NoExitState" - #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)"