Fixed an error in _lp_upwards_find, and enhanced it slightly.

_lp_upwards_find was using a single-quoted $@, not double-quoted, so
find was actually looking for files called '$@'.

In addition, once _lp_upwards_find finds the file it's looking for, it
breaks out so it doesn't need to always traverse to root.  I doubt
this actually saves much in practice, but it might as well be there.
This commit is contained in:
Taahir Ahmed 2013-10-18 21:19:43 -05:00 committed by Olivier Mengué
parent 31a86c9327
commit c7c57732a2

View File

@ -787,11 +787,21 @@ _lp_git_branch_color()
fi
}
# Search upwards through a directory structure looking for a file/folder with
# the given name. Used to avoid invoking 'hg' and 'bzr'.
_lp_upwards_find()
{
while [[ $PWD != / ]] ; do
find "$PWD"/ -maxdepth 1 -name '$@' 2> /dev/null
while [[ "$PWD" != "/" ]] ; do
# See if it's in the current directory.
local found=$(find "$PWD"/ -maxdepth 1 -name "$@" 2> /dev/null)
# If it is, then echo the path (or anything), and return.
if [[ -n found ]] ; then
echo $found
return
fi
cd ..
done
}
@ -806,7 +816,7 @@ _lp_hg_branch()
# 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
[[ -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.
@ -1034,7 +1044,7 @@ _lp_bzr_branch()
# 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
[[ -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.
@ -1059,7 +1069,7 @@ _lp_bzr_branch_color()
# 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
[[ -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.