* [PATCH] vcs_info: examples: use sed's q1 with +vi-git-untracked
@ 2015-04-02 13:21 Daniel Hahler
2015-04-02 15:42 ` Oliver Kiddle
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Hahler @ 2015-04-02 13:21 UTC (permalink / raw)
To: zsh-workers
From: Daniel Hahler <git@thequod.de>
This short-circuits the git command if there is any match.
Especially with `git ls-files` this is faster, although the additional
`--directory` (to only display directories, if they are untracked
completely, instead of all files in there) might make up for most of it.
---
Misc/vcs_info-examples | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples
index 766eb82..5337792 100644
--- a/Misc/vcs_info-examples
+++ b/Misc/vcs_info-examples
@@ -160,11 +160,11 @@ zstyle ':vcs_info:git*+set-message:*' hooks git-untracked
+vi-git-untracked(){
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
- git status --porcelain | grep '??' &> /dev/null ; then
+ ! git status --porcelain | sed -n '/^??/q1' ; then
# This will show the marker if there are any untracked files in repo.
# If instead you want to show the marker only if there are untracked
# files in $PWD, use:
- #[[ -n $(git ls-files --others --exclude-standard) ]] ; then
+ # ! git ls-files --others --directory --exclude-standard | sed -n q1; then
hook_com[staged]+='T'
fi
}
--
2.3.3.220.g9ab698f.dirty
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] vcs_info: examples: use sed's q1 with +vi-git-untracked
2015-04-02 13:21 [PATCH] vcs_info: examples: use sed's q1 with +vi-git-untracked Daniel Hahler
@ 2015-04-02 15:42 ` Oliver Kiddle
2015-04-27 3:01 ` Daniel Hahler
0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2015-04-02 15:42 UTC (permalink / raw)
To: zsh-workers
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.
Oliver
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] vcs_info: examples: use sed's q1 with +vi-git-untracked
2015-04-02 15:42 ` Oliver Kiddle
@ 2015-04-27 3:01 ` Daniel Hahler
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Hahler @ 2015-04-27 3:01 UTC (permalink / raw)
To: Zsh Hackers' List
-----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-----
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-04-27 3:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-02 13:21 [PATCH] vcs_info: examples: use sed's q1 with +vi-git-untracked Daniel Hahler
2015-04-02 15:42 ` Oliver Kiddle
2015-04-27 3:01 ` Daniel Hahler
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).