Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Improve vcs_info example for ahead/behind git commits
- X-seq: zsh-workers 48315
- From: "Daniel Shahaf" <d.s@xxxxxxxxxxxxxxxxxx>
- To: "Tim Lee" <progscriptclone@xxxxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: [PATCH] Improve vcs_info example for ahead/behind git commits
- Date: Mon, 29 Mar 2021 11:50:17 +0000
- Archived-at: <https://zsh.org/workers/48315>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-03/1b0343d9-87c2-4a0d-860f-30a390d7034d%40www.fastmail.com>
- In-reply-to: <20210329103927.qzky3fyevptfflvj@home-guest>
- List-id: <zsh-workers.zsh.org>
- References: <20210328213628.7rwz62bq5p2isd6b@home-guest> <20210329070611.GM18178@tarpaulin.shahaf.local2> <20210329093056.fegqam75id4yfkiq@home-guest> <ff17d1f9-d6ff-49bb-83d2-de0978ec61d4@www.fastmail.com> <20210329103927.qzky3fyevptfflvj@home-guest>
Tim Lee wrote on Mon, 29 Mar 2021 10:39 +00:00:
> > > > > diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples
> > > > > index 94b8a7b5e..36d4d3bf8 100644
> > > > > --- a/Misc/vcs_info-examples
> > > > > +++ b/Misc/vcs_info-examples
> > > > > @@ -179,14 +179,18 @@ function +vi-git-st() {
> > > > > local ahead behind
> > > > > local -a gitstatus
> > > > >
> > > > > - # for git prior to 1.7
> > > > > + # for git prior to 1.7.0
> > > > > # ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
> > > > > - ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
> > > > > + # for git 1.7.0 and 1.7.1
> > > > > + # ahead=$(git rev-list @{upstream}..HEAD 2>/dev/null | wc -l)
> > > > > + ahead=$(git rev-list --count @{upstream}..HEAD 2>/dev/null)
> > > > > (( $ahead )) && gitstatus+=( "+${ahead}" )
> > > >
> > > > The version of this function in my zshrc starts like this:
> > > > .
> > > > git rev-parse @{upstream} >/dev/null 2>&1 || return 0
> > > > local -a x=( $(git rev-list --left-right --count HEAD...@{upstream} ) )
> > >
> > > The snippet below displays N/M. How would you make it display +N/-M
> > > instead?
> >
> > Change the last line to hook_com[misc]="+${x[1]} -${x[2]}".
>
> But hook_com[misc]="+${x[1]} -${x[2]}" would display a '+0' and/or '-0'
> when the local git branch is not ahead-of or behind the remote branch.
>
> The existing example does not display '+0' or '-0'.
You didn't specify this when you asked. Anyway, if you want not to show
+0 or -0, then add the appropriate logic — e.g., «if (( x[2] )); then».
We're on -workers@ so I thought that'd go without saying.
A bit further out along the "readable"–"line noise" spectrum there is
this alternative:
hook_com[misc]="+$x[1]/-$x[2]"
hook_com[misc]=${${hook_com[misc]#'+0/'}%'/-0'}
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author