agnoster: fix bzr prompt with breezy installed (#8646)

* Change indentation to 2 spaces in prompt_bzr function
* Check if in a bzr repository and optimize bzr calls in prompt_bzr
This commit is contained in:
Marc Cornellà 2020-02-19 00:16:54 +01:00 committed by GitHub
parent eeb49bf5b0
commit c1b798aff3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -141,20 +141,26 @@ prompt_git() {
prompt_bzr() { prompt_bzr() {
(( $+commands[bzr] )) || return (( $+commands[bzr] )) || return
if (bzr status >/dev/null 2>&1); then
status_mod=`bzr status | head -n1 | grep "modified" | wc -m` # Test if bzr repository in directory hierarchy
status_all=`bzr status | head -n1 | wc -m` local dir="$PWD"
revision=`bzr log | head -n2 | tail -n1 | sed 's/^revno: //'` while [[ ! -d "$dir/.bzr" ]]; do
[[ "$dir" = "/" ]] && return
dir="${dir:h}"
done
local bzr_status status_mod status_all revision
if bzr_status=$(bzr status 2>&1); then
status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m)
status_all=$(echo -n "$bzr_status" | head -n1 | wc -m)
revision=$(bzr log -r-1 --log-format line | cut -d: -f1)
if [[ $status_mod -gt 0 ]] ; then if [[ $status_mod -gt 0 ]] ; then
prompt_segment yellow black prompt_segment yellow black "bzr@$revision ✚"
echo -n "bzr@"$revision "✚ "
else else
if [[ $status_all -gt 0 ]] ; then if [[ $status_all -gt 0 ]] ; then
prompt_segment yellow black prompt_segment yellow black "bzr@$revision"
echo -n "bzr@"$revision
else else
prompt_segment green black prompt_segment green black "bzr@$revision"
echo -n "bzr@"$revision
fi fi
fi fi
fi fi