Mercurial > hg > aboriginal
diff sources/functions.sh @ 903:5ffc758bf60a
Genericize search path traversal logic with pattern and command to apply to each file found.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 26 Nov 2009 02:37:36 -0600 |
parents | 726cac165450 |
children | 2ed667428dbd |
line wrap: on
line diff
--- a/sources/functions.sh Wed Nov 25 21:58:16 2009 -0600 +++ b/sources/functions.sh Thu Nov 26 02:37:36 2009 -0600 @@ -686,32 +686,27 @@ } -# Create a directory of symlinks to all binaries in a colon-separated path. +# Search a colon-separated path for files matching a pattern. -# Arguments are path to search, directory to populate, and (optionally) -# wrapper binary to symlink to instead of original binaries. +# Arguments are 1) path to search, 2) pattern, 3) command to run on each file. +# During command, $DIR/$FILE points to file found. -wrap_path() +path_search() { # For each each $PATH element, loop through each file in that directory, # and create a symlink to the wrapper with that name. In the case of # duplicates, keep the first one. - echo "$1" | sed 's/:/\n/g' | while read i + echo "$1" | sed 's/:/\n/g' | while read DIR do - ls -1 "$i" | while read j + find "$DIR" -maxdepth 1 -mindepth 1 | sed 's@.*/@@' | while read FILE do - if [ ! -z "$3" ] - then - ln -s "$3" "$2/$j" 2>/dev/null - else - ln -s "$i/$j" "$2/$j" 2>/dev/null - fi + eval "$3" # Output is verbose. Pipe it to dotprogress. - echo $j + echo $FILE done done }