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

Re: ${name/pattern/repl} with negated pattern



# neuhauser@xxxxxxxxxx / 2014-05-15 14:26:41 +0200:
> this snippet in zshcontrib(1):
> 
>     for i in "$@"; do
>         if [[ $i == sh/* ]]; then
>             [[ -n $s ]] && s=$s,
>             s=${s}$i
>         fi
>     done
> 
> can be reduced to
[...]

please find attached a tiny patch for Doc/Zsh/contrib.yo

-- 
roman
From 0e40d433f1087367b718d3426eb22aa2fdd921e9 Mon Sep 17 00:00:00 2001
From: Roman Neuhauser <rneuhauser@xxxxxxx>
Date: Thu, 15 May 2014 20:37:01 +0200
Subject: [PATCH] vcs_info: simplify +vi-hgbookmarks+LPAR()RPAR() in
 Doc/Zsh/contrib.yo

---
 Doc/Zsh/contrib.yo | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 9f59f23..efdb436 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -1504,22 +1504,15 @@ function +vi-hgbookmarks+LPAR()RPAR() {
     # This makes the bookmarks string use only those
     # bookmarks. If there's more than one, it
     # concatenates them using commas.
-    local s i
     # The bookmarks returned by `hg' are available in
     # the functions positional parameters.
-    (( $# == 0 )) && return 0
-    for i in "$@"; do
-        if [[ $i == sh/* ]]; then
-            [[ -n $s ]] && s=$s,
-            s=${s}$i
-        fi
-    done
+    local s="${(Mj:,:)@:#sh/*}"
     # Now, the communication with the code that calls
     # the hook functions is done via the hook_com[]
     # hash. The key, at which the `gen-hg-bookmark-string'
     # hook looks at is `hg-bookmark-string'. So:
     hook_com[hg-bookmark-string]=$s
-    # And to signal, that we want to use the sting we
+    # And to signal, that we want to use the string we
     # just generated, set the special variable `ret' to
     # something other than the default zero:
     ret=1
-- 
1.9.2



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