Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Tip of the day: vcs_info git: ahead/behind the upstream branch indication
- X-seq: zsh-users 21810
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Tip of the day: vcs_info git: ahead/behind the upstream branch indication
- Date: Tue, 23 Aug 2016 22:29:16 +0000
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=61uFT7tweSPu8ODybD+gTMGFnXo=; b=U7kLk6 9UpMgIK7ALqtspDN5DM1J5kLz/iiMxE2LhJy3aXN+RusVtlUsAdligBLa/8Qulbm DZ0jcKx/QTpB2PuJuPJEPvJQiM75yN5xMM/+xJlDS3llJkK9+RhSlNUo11jqh8my 1R09y0Q9Abhzap0sqIRzp2ywscRZV/iz9jdz8=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=61uFT7tweSPu8ODybD+gTMGFnXo=; b=cWVPf woBy5zIHSWGtaY8sXjYxpo+VxKHpxgJT0x7tnH4ErpgkzUUIQLb8HLRqP6KUUj6J UX5KwU2doJGC0HcOOU0IcEZdJ7yYCA/Vrlh5aauxM4Qe0++71YQwzVbTVfQq1Q5+ +CIaUXQWizezwRpC0isuFkJ3YKEpCFkMQJmTi4=
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
The following vcs_info hook adds an indication of whether the currently
checked out branch is ahead or behind its upstream branch:
# Add up/down arrows after branch name, if there are changes to pull/to push
zstyle ':vcs_info:git+post-backend:*' hooks git-post-backend-updown
+vi-git-post-backend-updown() {
git rev-parse @{upstream} >/dev/null 2>&1 || return
local -a x; x=( $(git rev-list --left-right --count HEAD...@{upstream} ) )
hook_com[branch]+="%f" # end coloring
(( x[2] )) && hook_com[branch]+="↓"
(( x[1] )) && hook_com[branch]+="↑"
return 0
}
For example:
### Behind upstream (after 'git fetch')
(git)-[master↓]-
%
### Ahead of upstream (before 'git push')
(git)-[master↑]-
%
### Diverged (each of upstream and local branch has commits the other doesn't have; a rebase/force-push situation)
(git)-[master↓↑]-
%
Messages sorted by:
Reverse Date,
Date,
Thread,
Author