um rename to handle piped input
This commit is contained in:
parent
230450b388
commit
7effa12c59
2 changed files with 35 additions and 5 deletions
|
|
@ -2,16 +2,31 @@
|
|||
|
||||
# Usage:
|
||||
|
||||
# > rename 100.md bar
|
||||
# > um rename 100.md foo
|
||||
# or
|
||||
# > rename 100.foo.md bar
|
||||
# > um rename 100.foo.md bar
|
||||
# or
|
||||
# > um last | um rename baz
|
||||
|
||||
# is equivalent to:
|
||||
# > mv 100.md 100.bar.md
|
||||
# > mv 100.md 100.foo.md
|
||||
# > mv 100.foo.md 100.bar.md
|
||||
# > mv 100.bar.md 100.baz.md
|
||||
|
||||
# accept piped input
|
||||
# https://unix.stackexchange.com/a/537581
|
||||
if [[ ! -t 0 ]]; then
|
||||
FROM=$(cat -)
|
||||
TO=$1
|
||||
else
|
||||
FROM=$1
|
||||
TO=$2
|
||||
fi
|
||||
|
||||
echo from: $FROM to: $TO
|
||||
|
||||
# split the args by a newline so that awk reads them as separate "records"
|
||||
mvcmd=`echo "$1
|
||||
$2" | awk -f $UMBASEPATH/rename.awk`
|
||||
mvcmd=`echo "$FROM
|
||||
$TO" | awk -f $UMBASEPATH/rename.awk`
|
||||
|
||||
mv $mvcmd
|
||||
|
|
|
|||
Loading…
Reference in a new issue