From 13fb3c958e3b0523a1415f4686953cc62c6f70b2 Mon Sep 17 00:00:00 2001 From: Olivier Dagenais Date: Sat, 19 Jul 2014 11:19:40 -0400 Subject: [PATCH 1/2] Add new "relative" option. This keeps the window title shorter. --- git-prompt.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 322164d..3962e3a 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -188,6 +188,19 @@ cwd_truncate() { [[ "$PWD" == "$HOME" ]] && cwd="~" return ;; + relative) + local git_dir=$(git rev-parse --git-dir 2>/dev/null) + local absolute_path=$(readlink -e $git_dir 2>/dev/null) + local parent_path=${absolute_path%%/.git} + local repo_name=${parent_path##/*/} + if [[ "$repo_name" == "" ]] + then + # default to "full" + return + fi + cwd="$repo_name${PWD##$parent_path}" + return + ;; *) ;; esac @@ -700,7 +713,6 @@ prompt_command_function() { fi cwd=${PWD/$HOME/\~} # substitute "~" - set_shell_label "${cwd##[/~]*/}/" # default label - path last dir parse_virtualenv_status parse_vcs_status @@ -713,6 +725,7 @@ prompt_command_function() { # if cwd_cmd have back-slash, then assign it value to cwd # else eval cwd_cmd, cwd should have path after exection eval "${cwd_cmd/\\/cwd=\\\\}" + set_shell_label "${cwd}" PS1="$colors_reset$rc$head_local$color_who_where$dir_color$cwd$tail_local$dir_color$prompt_char $colors_reset" From 9b0ee0102ef8f0ad2e69ca471cc0306c28a5f482 Mon Sep 17 00:00:00 2001 From: Olivier Dagenais Date: Fri, 28 May 2021 13:29:50 -0400 Subject: [PATCH 2/2] refactor: re-use git_dir & skip if n/a --- git-prompt.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 3962e3a..55b09cc 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -189,16 +189,15 @@ cwd_truncate() { return ;; relative) - local git_dir=$(git rev-parse --git-dir 2>/dev/null) - local absolute_path=$(readlink -e $git_dir 2>/dev/null) - local parent_path=${absolute_path%%/.git} - local repo_name=${parent_path##/*/} - if [[ "$repo_name" == "" ]] - then - # default to "full" - return + if [[ $git_module = "on" && -d ${git_dir} ]]; then + local absolute_path=$(readlink -e $git_dir 2>/dev/null) + local parent_path=${absolute_path%%/.git} + local repo_name=${parent_path##/*/} + if [[ -n "$repo_name" ]] + then + cwd="$repo_name${PWD##$parent_path}" + fi fi - cwd="$repo_name${PWD##$parent_path}" return ;; *)