Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] vcs_info: examples: use sed's q1 with +vi-git-untracked



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02.04.2015 17:42, Oliver Kiddle wrote:
> Daniel Hahler wrote:
>>
>> This short-circuits the git command if there is any match.
>>
>> Especially with `git ls-files` this is faster, although the additional
> 
> Unfortunately, the exit code after q is a GNU sed extension so this now
> breaks on non-Linux systems.
> 
> Portable alternatives that come to mind include: piping to head -1 and using
> $pipestatus, using sed q and testing for output, using awk. There's
> probably something better than those, however.

Using "grep -q" would probably solve it already for the "git status"
case (which uses grep already), and "| grep -q ." could be used for
"git ls-files".

I've also found that "git status" can be noticably slower than "ls-files",
so I'd suggest to use this instead.

Additionally, the hook appears to be only called if there's a gitdir anyway,
so the check ("git rev-parse --is-inside-work-tree") could be removed.

I am using this currently:

  # vcs_info: git: Show marker (✗) if there are untracked files in repository.
  # (via %c).
  function +vi-git-untracked() {
      [[ $1 == 0 ]] || return  # do this only once for vcs_info_msg_0_.

      local gitdir=${vcs_comm[gitdir]}

      if command git --git-dir $gitdir ls-files --other --directory --exclude-standard | command grep -q .; then
          hook_com[staged]+='✗ '
      fi
  }


What do you think?
Should I update the patch?


Regards,
Daniel.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iD8DBQFVPaabfAK/hT/mPgARAgfCAJ40olRYsAJfMQtoLcfjkQow2XwEJACgg38X
itDWMXo5xDpm5sykhCezxYY=
=YrSU
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author