From 85de63d5040180ca762f39000b0c2253be70b3e6 Mon Sep 17 00:00:00 2001 From: Stephan Knauss Date: Fri, 11 Nov 2016 13:26:47 +0100 Subject: [PATCH 1/2] extend gp_truncate_pwd to accept parameter with max pwd length If length is passed as a parameter, the given length will be used to truncate the pwd. If nothing is specified it defaults to 1/3 of the terminal width. --- gitprompt.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 9ff5b42..0004889 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -585,10 +585,11 @@ function is_function { } # Helper function that truncates $PWD depending on window width +# Optionally specify maximum length as parameter (defaults to 1/3 of terminal) function gp_truncate_pwd { local tilde="~" local newPWD="${PWD/#${HOME}/${tilde}}" - local pwdmaxlen=$((${COLUMNS:-80}/3)) + local pwdmaxlen=${1:-$((${COLUMNS:-80}/3))} [ ${#newPWD} -gt $pwdmaxlen ] && newPWD="...${newPWD:3-$pwdmaxlen}" echo -n "$newPWD" } From deae96f1bff6849ea334ed67652506f49c38360c Mon Sep 17 00:00:00 2001 From: Stephan Knauss Date: Fri, 11 Nov 2016 13:35:14 +0100 Subject: [PATCH 2/2] add gp_truncate_pwd default parameter documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 93df352..fbfe776 100644 --- a/README.md +++ b/README.md @@ -228,7 +228,7 @@ function prompt_callback { - There are two helper functions that can be used within `prompt_callback`: - `gp_set_window_title ` - sets the window title to the given string (should work for XTerm type terminals like in OS X or Ubuntu) - - `gp_truncate_pwd` - a function that returns the current PWD truncated to fit the current terminal width + - `gp_truncate_pwd` - a function that returns the current PWD truncated to fit the current terminal width. Specify the length to truncate to as a parameter. Otherwise it defaults to 1/3 of the terminal width. - If you want to show the git prompt only if you are in a git repository you can set ``GIT_PROMPT_ONLY_IN_REPO=1`` before sourcing the gitprompt script