From 58b090141a0856b078b9ac6f2917c4fe6f7997ea Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Sun, 1 Dec 2019 09:38:51 -0600 Subject: [PATCH] .bashrc: Update prompt_color() to use `realpath` to get canonical $HOME Use `realpath` to get canonical $HOME file-path. This is mainly relevant in situations where $HOME is under a symlink, where there will be a difference between the symbolic vs canonical values. --- .bashrc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.bashrc b/.bashrc index 8bb830f..0ecfef9 100644 --- a/.bashrc +++ b/.bashrc @@ -220,12 +220,16 @@ prompt_compact() { } prompt_color() { - # if git and the git bash_completion scripts are installed, use __git_ps1() to show current branch info. - # never show branch info for $HOME (dotfiles) repo. - # use the following to exclude a given repo: `git config --local --bool --add bash.hidePrompt true` + # if git and the git bash_completion scripts are installed, use __git_ps1() + # to show current branch info. + # - never show branch info for $HOME (dotfiles) repo. + # - optionally hide branch info for git repo's with `bash.hidePrompt` + # config flag set. use the following to exclude a given repo: + # `git config --local --bool --add bash.hidePrompt true` if [ -n "$(type -P git)" -a "$(type -t __git_ps1)" = "function" ]; then + home_canonical="$(test -n "$(type -P realpath)" && realpath $HOME || echo $HOME)" PS_GIT='$(test -n "$(__git_ps1 %s)" && - test "$(git rev-parse --show-toplevel)" != "$HOME" && + test "$(git rev-parse --show-toplevel)" != "$home_canonical" && test "$(git config --bool bash.hidePrompt)" != "true" && __git_ps1 "{\[\033[0;40;36m\]%s\[\033[0;90m\]}")' export GIT_PS1_SHOWDIRTYSTATE=1 -- 2.43.0