zshrc: new function rundirs() to run shell functions in a bunch of directories.
authorBernhard Tittelbach <bernhard@tittelbach.org>
Fri, 8 Jul 2011 11:16:37 +0000 (13:16 +0200)
committerMichael Prokop <mika@grml.org>
Thu, 21 Jul 2011 15:30:06 +0000 (17:30 +0200)
doc/grmlzshrc.t2t
etc/zsh/zshrc

index 271cedb..362c67b 100644 (file)
@@ -812,6 +812,11 @@ Reloads functions given as parameters.
 Checks whether a regular expression (first parameter) matches a string
 (second parameter) using perl.
 
+: **rundirs()**
+Takes as first parameter a quoted string containing an exectuable command or function with arguments.
+Following that it takes a bunch of directories, which will then be traversed, executing the
+first argument in each one. E.g.: rundirs purge . **/*(/-/)
+
 : **salias()**
 Creates an alias whith sudo prepended, if $EUID is not zero. Run "salias -h"
 for details. See also xunfunction() below.
index 399ac4f..abe6a22 100644 (file)
@@ -3650,6 +3650,13 @@ if is439 && [[ -d /dev/disk/by-id/ ]]; then
     }
 fi
 
+#f5# run command or function in a list of directories
+rundirs() {
+  local d CMD STARTDIR=$PWD
+  CMD=$1; shift
+  ( for d ($@) {cd -q $d && { print cd $d; ${(z)CMD} ; cd -q $STARTDIR }} )
+}
+
 # Translate DE<=>EN
 # 'translate' looks up fot a word in a file with language-to-language
 # translations (field separator should be " : "). A typical wordlist looks