zsh-users
 help / color / mirror / code / Atom feed
* vcs_info: can't get %c and %u to perform as expected
@ 2011-05-06  1:58 Alex Satrapa
  2011-05-06  5:19 ` Frank Terbeck
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Satrapa @ 2011-05-06  1:58 UTC (permalink / raw)
  To: zsh-users

I'm trying to set up git/hg information in my ZSH prompt. At this point I can do the following without using vcs_info (the RPROMPT):

 10:59 .zsh.d ➤                    ±master!

Here you see the time, the name of the current directory (the path is summarised in the window title), then over on the right hand side the ± means it's a git repository (there would be a ☿ if it was Mercurial), the current branch name and a '!' to indicate that the repository is dirty.

I'm doing this using my customised version of Oh My ZSH: https://github.com/AlexSatrapa/oh-my-zsh - check my "alex" theme, which is based on "arrow" and "deiter".

While another contributor was trying to get a similar change pulled back into the master Oh My ZSH, it was suggested that the VCS stuff be done using vcs_info, which is a common contrib shipped with ZSH. To this end I have tried the following commands in order to emulate my current RPROMPT information:

11:06 .oh-my-zsh ➤ touch blah                                                    ±master 
11:07 .oh-my-zsh ➤ autoload vcs_info                                             ±master!
11:07 .oh-my-zsh ➤ zstyle ':vcs_info:*:*:*' use-prompt-escapes true              ±master!
11:07 .oh-my-zsh ➤ zstyle ':vcs_info:*:*:*' check-for-changes true               ±master!
11:07 .oh-my-zsh ➤ vcs_info ; echo $vcs_info_msg_0_                              ±master!
(git)-[master]-
11:08 .oh-my-zsh ➤ zstyle ':vcs_info:*' formats '%b%u%c'                         ±master!
[m.oh-my-zsh'%                                                                            
11:09 .oh-my-zsh ➤ vcs_info ; echo $vcs_info_msg_0_                              ±master!
master%u%c

I am expecting that setting 'use-prompt-escapes' to true will cause the %u and %c escapes to be replaced with 'U' and 'S' if the current repository has unstaged or staged changes (as per the ZSH manual). Note that the "!" on my current RPROMPT will be set if the repository is "dirty" (i.e.: has any changes at all, tracked or untracked), so there are in fact unstaged changes in this directory.

Does anyone have a suggestion as to what I'm doing wrong?  As the adage goes, "when reality doesn't meet your expectations, it's not reality that has to change."  What am I missing, which is stopping vcs_info from behaving the way I'm expecting it to?

My reference documentation is only §26.4 of the ZSH manual, "Gathering information from version control systems", and a bunch of scripts provided by other people such as https://github.com/blueyed/oh-my-zsh/blob/master/themes/blueyed.zsh-theme

At this point I haven't been able to find any "Dummy's Guide To vcs_info*" :(

Alex


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: vcs_info: can't get %c and %u to perform as expected
  2011-05-06  1:58 vcs_info: can't get %c and %u to perform as expected Alex Satrapa
@ 2011-05-06  5:19 ` Frank Terbeck
  2011-05-06  6:07   ` Alex Satrapa
  0 siblings, 1 reply; 7+ messages in thread
From: Frank Terbeck @ 2011-05-06  5:19 UTC (permalink / raw)
  To: Alex Satrapa; +Cc: zsh-users, Seth House

Alex Satrapa wrote:
> I'm trying to set up git/hg information in my ZSH prompt. At this
> point I can do the following without using vcs_info (the RPROMPT):
>
>  10:59 .zsh.d ➤                    ±master!
>
> Here you see the time, the name of the current directory (the path is
> summarised in the window title), then over on the right hand side the
> ± means it's a git repository (there would be a ☿ if it was
> Mercurial), the current branch name and a '!' to indicate that the
> repository is dirty.
[...]
> I am expecting that setting 'use-prompt-escapes' to true will cause

`use-prompt-escapes' has nothing to do with normal `vcs_info' execution,
as documented it is *only* used by `vcs_info_lastmsg'.

> the %u and %c escapes to be replaced with 'U' and 'S' if the current
> repository has unstaged or staged changes (as per the ZSH
> manual). Note that the "!" on my current RPROMPT will be set if the
> repository is "dirty" (i.e.: has any changes at all, tracked or
> untracked), so there are in fact unstaged changes in this directory.

You need to set the `check-for-changes' style. After that, it should
work.  I'm not sure if with the hg backend, it's also required to set
the `get-revision' style (Seth?).  If it is, that's missing from the
manual and should be fixed.

[...]
> At this point I haven't been able to find any "Dummy's Guide To
> vcs_info*" :(

There is a file `Misc/vcs_info-examples', which is included with newer
versions of zsh. If contains a number of examples for `vcs_info' as its
name suggests.

There is also a blog entry by Seth (whom I've Cc:ed) which gives
pointers towards using `vcs_info' with mercurial. He extended the hg
backend a lot, so he knows what he's doing:

  <http://eseth.org/2010/hg-in-zsh/>


Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: vcs_info: can't get %c and %u to perform as expected
  2011-05-06  5:19 ` Frank Terbeck
@ 2011-05-06  6:07   ` Alex Satrapa
  2011-05-06  6:35     ` Frank Terbeck
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Satrapa @ 2011-05-06  6:07 UTC (permalink / raw)
  To: zsh-users; +Cc: Seth House

On 06/05/2011, at 15:19 , Frank Terbeck wrote:

> You need to set the `check-for-changes' style. After that, it should
> work.

It appears that the %c and %u escapes were added some time between 4.3.9 (stock standard Mac OS X Snow Leopard 10.6.7) and 4.3.11 (installed via MacPorts).  Having upgraded to 4.3.11 I can now get the "staged" flag to show up:

15:25 ~project ➤ zstyle ':vcs_info:*' formats '%b/%c/%u'                       ±master
15:28 ~project ➤ vcs_info ; echo $vcs_info_msg_0_                              ±master
master//
15:28 ~project ➤ touch blah                                                    ±master
15:28 ~project ➤ vcs_info ; echo $vcs_info_msg_0_                             ±master!
master//
15:28 ~project ➤ git add blah                                                 ±master!
15:29 ~project ➤ vcs_info ; echo $vcs_info_msg_0_                             ±master!
master/S/

>  I'm not sure if with the hg backend, it's also required to set
> the `get-revision' style (Seth?).  If it is, that's missing from the
> manual and should be fixed.

15:36 ~hg-stuff ➤ zstyle -L ':vcs_info:*'                                        ☿trunk
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' enable ALL
zstyle ':vcs_info:*' formats %b/%c/%u
zstyle ':vcs_info:*' get-revision true

15:36 ~hg-stuff ➤ touch blah                                                      ☿trunk
15:36 ~hg-stuff ➤ vcs_info ; echo $vcs_info_msg_0_                               ☿trunk?
trunk:ceaa49e8a06cc8880d434b8b3c329a4598f5b8be:0//
15:36 ~hg-stuff ➤ hg add blah                                                    ☿trunk?
15:37 ~hg-stuff ➤ zstyle ':vcs_info:*' get-revision false                        ☿trunk+
15:38 ~hg-stuff ➤ vcs_info ; echo $vcs_info_msg_0_                               ☿trunk+
trunk//
15:38 ~hg-stuff ➤ zstyle ':vcs_info:*' get-revision true                         ☿trunk+
15:38 ~hg-stuff ➤ vcs_info ; echo $vcs_info_msg_0_                               ☿trunk+
trunk:ceaa49e8a06cc8880d434b8b3c329a4598f5b8be:0//U

So apparently the get-revision style needs to be true in order to get the 'unstaged' changes flag to show up for Mercurial.

But now I'm even more confused since vcs_info's "staged" and "unstaged" changes don't conform to my expectations. I'm expecting that my working copy is in one of three states: "dirty" (signified by '?' above), having "added but uncommitted" changes (see '+' above), or unchanged from VCS. Thus (by my thinking), "unstaged" should conform to "dirty", "staged" should conform to "added but uncommitted" - but it looks like that's not the case.

> There is a file `Misc/vcs_info-examples', which is included with newer
> versions of zsh. If contains a number of examples for `vcs_info' as its
> name suggests.

I have been working through that and other sources. My initial problem getting the %c/%u escapes to do anything was due to user error (using the wrong version of ZSH or at least the vcs_info function).

>  <http://eseth.org/2010/hg-in-zsh/>

I'll keep note of that for sure!

Regards
Alex


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: vcs_info: can't get %c and %u to perform as expected
  2011-05-06  6:07   ` Alex Satrapa
@ 2011-05-06  6:35     ` Frank Terbeck
  2011-05-06  7:57       ` Alex Satrapa
  0 siblings, 1 reply; 7+ messages in thread
From: Frank Terbeck @ 2011-05-06  6:35 UTC (permalink / raw)
  To: Alex Satrapa; +Cc: zsh-users, Seth House

(Could you limit lines of text to something around 75? It's a little
hard to read these overlong lines.)

Alex Satrapa wrote:
> On 06/05/2011, at 15:19 , Frank Terbeck wrote:
[...]
> So apparently the get-revision style needs to be true in order to get
> the 'unstaged' changes flag to show up for Mercurial.

Okay. Then that needs to be documented. (I'll look into it in the
evening - Europe's evening, fwiw.)

> But now I'm even more confused since vcs_info's "staged" and
> "unstaged" changes don't conform to my expectations. I'm expecting
> that my working copy is in one of three states: "dirty" (signified by
> '?' above), having "added but uncommitted" changes (see '+' above), or
> unchanged from VCS. Thus (by my thinking), "unstaged" should conform
> to "dirty", "staged" should conform to "added but uncommitted" - but
> it looks like that's not the case.

Well, the `hg' backend doesn't support `staged' (that's documented,
too). Mercurial doesn't expose its staging area like git does, so we
can't tell if there are staged changes 
AFAIK, for it.

>> There is a file `Misc/vcs_info-examples', which is included with newer
>> versions of zsh. If contains a number of examples for `vcs_info' as its
>> name suggests.
>
> I have been working through that and other sources. My initial problem
> getting the %c/%u escapes to do anything was due to user error (using
> the wrong version of ZSH or at least the vcs_info function).
>
>>  <http://eseth.org/2010/hg-in-zsh/>
>
> I'll keep note of that for sure!

That'll need a pretty recent version of vcs_info, too. He's using looks
in there. I can't remember if those were part of 4.3.11.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: vcs_info: can't get %c and %u to perform as expected
  2011-05-06  6:35     ` Frank Terbeck
@ 2011-05-06  7:57       ` Alex Satrapa
  2011-05-06 17:53         ` Seth House
  2011-05-06 18:02         ` Seth House
  0 siblings, 2 replies; 7+ messages in thread
From: Alex Satrapa @ 2011-05-06  7:57 UTC (permalink / raw)
  To: Frank Terbeck; +Cc: zsh-users, Seth House

On 06/05/2011, at 16:35 , Frank Terbeck wrote:

> Well, the `hg' backend doesn't support `staged' (that's documented,
> too). Mercurial doesn't expose its staging area like git does, so we
> can't tell if there are staged changes 
> AFAIK, for it.

My confusion is thus down to what vcs_info means by "staged" and
"unstaged". With my current system for Mercurial (and soon, with
git) I can display a symbol when there are new files or edits, a
different symbol when there are changes ready to be committed
(i.e.: "added").

For now, my quest is to figure out if/how vcs_info can expose
the information from 'git status —porcelain' or 'hg status' to a
ZSH prompt.  Both output something along the lines of
 ? - a new file
 A - a new file to be added on next commit
 M - existing file with changes for next commit

Thus matching for "^?", "^A" or "^M" can tell me what I'm after.
In my nomenclature, the "?" in the status output means "unknown
files", while "A" or "M" mean "uncommitted changes". In both
cases I can simply call the repository "dirty".

Which all boils down to presenting a ZSH prompt that indicates
to the user, "there's nothing to do here" or "it's dirty, you
need to clean up."  Ultimately I will simply be presenting
the branch name in a different colour to indicate the status,
rather than cluttering up the RPROMPT with extra characters.

All the extra details (hg patches applied, branch name,
revision number, etc) are extraneous to my needs: I can find
that information by executing the commands appropriate for the
VCS. I don't want my prompt cluttered up with more information
that what I absolutely need (while Seth's nethack prompt is
*very cute* and *very clever*, it's not my style).

I now have something interesting to play with over the weekend.

Regards
Alex


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: vcs_info: can't get %c and %u to perform as expected
  2011-05-06  7:57       ` Alex Satrapa
@ 2011-05-06 17:53         ` Seth House
  2011-05-06 18:02         ` Seth House
  1 sibling, 0 replies; 7+ messages in thread
From: Seth House @ 2011-05-06 17:53 UTC (permalink / raw)
  To: zsh-users

Alex Satrapa <grail <at> goldweb.com.au> writes:
> My confusion is thus down to what vcs_info means by "staged" and
> "unstaged".

That is Git terminology. "Unstaged" in Mercurial terminology is when
your working directory has uncommitted changes -- i.e., your working
directory is not "clean".

> For now, my quest is to figure out if/how vcs_info can expose
> the information from 'git status —porcelain' or 'hg status' to a
> ZSH prompt.

This is information is already available in the Mercurial backend; if
your working directory is not clean it will display a "U" character. In
my vcs_info configuration I have the following style to make the display
more similar to the `hg id` output.

zstyle ':vcs_info:hg*:*' unstagedstr "+"

If you want to change the color of the branch name instead, you can
easily write a short hook to do so.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: vcs_info: can't get %c and %u to perform as expected
  2011-05-06  7:57       ` Alex Satrapa
  2011-05-06 17:53         ` Seth House
@ 2011-05-06 18:02         ` Seth House
  1 sibling, 0 replies; 7+ messages in thread
From: Seth House @ 2011-05-06 18:02 UTC (permalink / raw)
  To: zsh-users

Alex Satrapa <grail <at> goldweb.com.au> writes:
> My confusion is thus down to what vcs_info means by "staged" and
> "unstaged". With my current system for Mercurial [...] I can display a
> symbol when there are new files or edits, a different symbol when
> there are changes ready to be committed (i.e.: "added").

...I suck at reading. If you want to change the branch name to a
different color depending on all these three criteria, then you will
need to write a hook that parses the output of `hg status`. The
Mercurial backend of vcs_info goes to great lengths to only invoke
Mercurial one time -- any more than that and I found the prompt would
draw too slowly for real use. If you find the same, you may want to set
the use-simple style to have vcs_info invoke `hexdump` instead then you
can invoke `hg status` yourself.

When you're done, this sounds like it would be a good candidate for
inclusion in the vcs_info-examples file. Let me know if I can answer any
questions or help out. :)


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-05-06 18:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-06  1:58 vcs_info: can't get %c and %u to perform as expected Alex Satrapa
2011-05-06  5:19 ` Frank Terbeck
2011-05-06  6:07   ` Alex Satrapa
2011-05-06  6:35     ` Frank Terbeck
2011-05-06  7:57       ` Alex Satrapa
2011-05-06 17:53         ` Seth House
2011-05-06 18:02         ` Seth House

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).