From: Bernhard Tittelbach Date: Fri, 8 Jul 2011 11:16:37 +0000 (+0200) Subject: zshrc: new function rundirs() to run shell functions in a bunch of directories. X-Git-Tag: v0.4.00~13 X-Git-Url: http://git.grml.org/?p=grml-etc-core.git;a=commitdiff_plain;h=01fe02eb822310ffaace189928cfa9108c4fc1ab zshrc: new function rundirs() to run shell functions in a bunch of directories. --- diff --git a/doc/grmlzshrc.t2t b/doc/grmlzshrc.t2t index 271cedb..362c67b 100644 --- a/doc/grmlzshrc.t2t +++ b/doc/grmlzshrc.t2t @@ -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. diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 399ac4f..abe6a22 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -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