Added "upwards find" tests for expensive dvcs.
Mercurial and Bazaar are written in Python, which, on my system, causes a noticeable hitch in the prompt generation when changing directories. I have added code that, before invoking the 'hg' or 'bzr' executables, first tests if we could possibly be in a bazaar or hg repository checkout by traversing the directory structure upwards to the root, looking for an '.hg' or '.bzr' folder. At least for me, this makes the prompt instantaneous. There may be more elegant solutions to this problem, but this one works.
This commit is contained in:
parent
7fe87a5cf5
commit
31a86c9327
37
liquidprompt
37
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 #
|
# MERCURIAL #
|
||||||
|
|
||||||
# Get the branch name of the current directory
|
# Get the branch name of the current directory
|
||||||
_lp_hg_branch()
|
_lp_hg_branch()
|
||||||
{
|
{
|
||||||
[[ "$LP_ENABLE_HG" != 1 ]] && return
|
[[ "$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
|
local branch
|
||||||
branch="$(hg branch 2>/dev/null)"
|
branch="$(hg branch 2>/dev/null)"
|
||||||
[[ $? -eq 0 ]] && _lp_escape "$branch"
|
|
||||||
|
|
||||||
|
[[ $? -eq 0 ]] && _lp_escape "$branch"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set a color depending on the branch state:
|
# Set a color depending on the branch state:
|
||||||
@ -1013,6 +1030,15 @@ _lp_fossil_branch_color()
|
|||||||
_lp_bzr_branch()
|
_lp_bzr_branch()
|
||||||
{
|
{
|
||||||
[[ "$LP_ENABLE_BZR" != 1 ]] && return
|
[[ "$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
|
local branch
|
||||||
branch="$(bzr nick 2> /dev/null)"
|
branch="$(bzr nick 2> /dev/null)"
|
||||||
[[ $? -ne 0 ]] && return
|
[[ $? -ne 0 ]] && return
|
||||||
@ -1029,6 +1055,15 @@ _lp_bzr_branch()
|
|||||||
_lp_bzr_branch_color()
|
_lp_bzr_branch_color()
|
||||||
{
|
{
|
||||||
[[ "$LP_ENABLE_BZR" != 1 ]] && return
|
[[ "$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
|
local output
|
||||||
output="$(bzr version-info --check-clean --custom --template='{branch_nick} {revno} {clean}' 2> /dev/null)"
|
output="$(bzr version-info --check-clean --custom --template='{branch_nick} {revno} {clean}' 2> /dev/null)"
|
||||||
[[ $? -ne 0 ]] && return
|
[[ $? -ne 0 ]] && return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user