diff --git a/liquidprompt b/liquidprompt index 26021eb..51f90e0 100755 --- a/liquidprompt +++ b/liquidprompt @@ -788,16 +788,33 @@ _lp_git_branch_color() } +_lp_upwards_find() +{ + while [[ $PWD != / ]] ; do + find "$PWD"/ -maxdepth 1 -name '$@' 2> /dev/null + cd .. + done +} + # MERCURIAL # # Get the branch name of the current directory _lp_hg_branch() { [[ "$LP_ENABLE_HG" != 1 ]] && return + + # First do a simple search to avoid having to invoke hg -- at least on my + # machine, the python startup causes a noticeable hitch when changing + # directories. + [[ -z $(_lp_upwards_find '.hg') ]] && return + + # We found an .hg folder, so we need to invoke hg and see if we're actually + # in a repository. + local branch branch="$(hg branch 2>/dev/null)" - [[ $? -eq 0 ]] && _lp_escape "$branch" + [[ $? -eq 0 ]] && _lp_escape "$branch" } # Set a color depending on the branch state: @@ -1013,6 +1030,15 @@ _lp_fossil_branch_color() _lp_bzr_branch() { [[ "$LP_ENABLE_BZR" != 1 ]] && return + + # First do a simple search to avoid having to invoke bzr -- at least on my + # machine, the python startup causes a noticeable hitch when changing + # directories. + [[ -z $(_lp_upwards_find '.bzr') ]] && return + + # We found an .bzr folder, so we need to invoke bzr and see if we're + # actually in a repository. + local branch branch="$(bzr nick 2> /dev/null)" [[ $? -ne 0 ]] && return @@ -1029,6 +1055,15 @@ _lp_bzr_branch() _lp_bzr_branch_color() { [[ "$LP_ENABLE_BZR" != 1 ]] && return + + # First do a simple search to avoid having to invoke bzr -- at least on my + # machine, the python startup causes a noticeable hitch when changing + # directories. + [[ -z $(_lp_upwards_find '.bzr') ]] && return + + # We found an .bzr folder, so we need to invoke bzr and see if we're + # actually in a repository. + local output output="$(bzr version-info --check-clean --custom --template='{branch_nick} {revno} {clean}' 2> /dev/null)" [[ $? -ne 0 ]] && return