diff options
author | Niklas Hofer <niklas+dev@lanpartei.de> | 2009-05-28 01:32:05 +0200 |
---|---|---|
committer | Niklas Hofer <niklas+dev@lanpartei.de> | 2009-05-28 01:32:05 +0200 |
commit | ab038a3b0d914d669c3aace89d8c327c7efb09ba (patch) | |
tree | c0cbe5b119c4b6d789a536e960d969780e54f3ac /git-prompt.sh | |
parent | -- optimization: one time processing moved to post-config (diff) | |
download | git-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
Diffstat (limited to 'git-prompt.sh')
-rwxr-xr-x | git-prompt.sh | 15 |
1 files changed, 13 insertions, 2 deletions
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 |