From b3194732a0805c16a760e85eaa224a54ae5657af Mon Sep 17 00:00:00 2001 From: oGre Date: Fri, 11 Sep 2015 09:43:33 +0200 Subject: [PATCH] Custom theme using prompt_callback --- themes/TruncatedPwd_WindowTitle.bgptheme | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 themes/TruncatedPwd_WindowTitle.bgptheme diff --git a/themes/TruncatedPwd_WindowTitle.bgptheme b/themes/TruncatedPwd_WindowTitle.bgptheme new file mode 100644 index 0000000..3ab9a75 --- /dev/null +++ b/themes/TruncatedPwd_WindowTitle.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=Default_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=" _LAST_COMMAND_INDICATOR_\n${White}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" _LAST_COMMAND_INDICATOR_\n${White}${Time12a}${ResetColor} # " +} + +reload_git_prompt_colors "TruncatedPwd_WindowTitle"