summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Hofer <niklas+dev@lanpartei.de>2009-05-28 01:32:05 +0200
committerNiklas Hofer <niklas+dev@lanpartei.de>2009-05-28 01:32:05 +0200
commitab038a3b0d914d669c3aace89d8c327c7efb09ba (patch)
treec0cbe5b119c4b6d789a536e960d969780e54f3ac
parent-- optimization: one time processing moved to post-config (diff)
downloadgit-prompt-ab038a3b0d914d669c3aace89d8c327c7efb09ba.tar.gz
git-prompt-ab038a3b0d914d669c3aace89d8c327c7efb09ba.tar.bz2
git-prompt-ab038a3b0d914d669c3aace89d8c327c7efb09ba.zip
truncate working path until it fits into max_pwd_length or cannot be shortened anymore
-rw-r--r--git-prompt.conf6
-rwxr-xr-xgit-prompt.sh15
2 files changed, 19 insertions, 2 deletions
diff --git a/git-prompt.conf b/git-prompt.conf
index acdc98c..f40284b 100644
--- a/git-prompt.conf
+++ b/git-prompt.conf
@@ -27,6 +27,12 @@
## default_host="ahp" # remote host is always shown
## default_domain="lvvnet"
+########################################################### PWD
+## the working path will be truncated by cutting of chars
+## of the components
+
+# max_pwd_length=30
+# min_chars_per_pwd=1
########################################################### COLOR
diff --git a/git-prompt.sh b/git-prompt.sh
index e3ca24d..2412823 100755
--- a/git-prompt.sh
+++ b/git-prompt.sh
@@ -44,6 +44,8 @@
detached_vcs_color=${detached_vcs_color:-RED}
max_file_list_length=${max_file_list_length:-100}
+ max_pwd_length=${max_pwd_length:-30}
+ min_chars_per_pwd=${min_chars_per_pwd:-1}
@@ -140,6 +142,14 @@
export who_where
+truncate_working_directory() {
+ pwd=`echo $PWD | sed "s:^${HOME}:~:"`
+ chars_per_dir=5
+ while [[ $((chars_per_dir--)) -gt $((min_chars_per_pwd)) && `echo ${pwd} | wc -m` -gt $((max_pwd_length)) ]]; do
+ pwd=`echo ${pwd} | sed "s:[^\/~]*\(/.\{${chars_per_dir}\}\):\1:g"`
+ done
+ unset chars_per_dir
+}
set_shell_title() {
@@ -509,9 +519,10 @@ prompt_command_function() {
set_shell_title "$PWD/"
parse_vcs_status
- PS1="$colors_reset$rc$head_local$label$color_who_where$dir_color\w$tail_local$dir_color> $colors_reset"
+ truncate_working_directory
+ PS1="$colors_reset$rc$head_local$label$color_who_where$dir_color$pwd$tail_local$dir_color> $colors_reset"
- unset head_local tail_local
+ unset head_local tail_local pwd
}
PROMPT_COMMAND=prompt_command_function