1
|
#!/bin/sh
|
2
|
# Expands bash-style {} expressions.
|
3
|
# See <http://www.gnu.org/software/bash/manual/bash.html#Brace-Expansion>.
|
4
|
# Filters each line from stdin to stdout.
|
5
|
# Warning: Due to shell limitations, a blank line will be interpreted as EOF.
|
6
|
|
7
|
sedEreFlag="$(test "$(uname)" = Darwin && echo E || echo r)"
|
8
|
|
9
|
sed () { "$(which sed)" -"$sedEreFlag" "$@";}
|
10
|
|
11
|
echoEach () { local line; for line in "$@"; do echo "$line"; done; }
|
12
|
|
13
|
braceKeepRe="./'{'"
|
14
|
braceKeepRepl="./{"
|
15
|
|
16
|
while true; do
|
17
|
line="$(head -1)" # get next line from stdin; $() strips trailing newlines
|
18
|
test -z "$line" && break # EOF if no line or empty line
|
19
|
line="$(echo "$line"|sed -e "s/[^{,}]+/'&'/g")" # escape special chars
|
20
|
line="${line//$braceKeepRe/$braceKeepRepl}" # don't expand ./{
|
21
|
eval "echoEach $line" # brace-expand $line
|
22
|
done
|