pmv.sh (474B)
1 #!/bin/sh 2 # Copyright 2023 Jacob R. Edwards <jacob@jacobedwards.org> 3 # Pipe move 4 # 5 # Uses bmv to rename the files provided through the standard input 6 # by filtering them through the given command. 7 8 fifo=/tmp/pipe$$ 9 10 usage() { 11 echo 'usage: pmv [-bmv-flags] command [arguments ...]' 1>&2 12 exit 1 13 } 14 15 set -e 16 17 case "$1" in 18 (-*) 19 flags="$1" 20 shift ;; 21 esac 22 23 case $# in 24 (0) usage ;; 25 esac 26 27 mkfifo $fifo 28 trap 'rm -f $fifo' 0 INT TERM 29 tee $fifo | "$@" | bmv $flags $fifo || 30 usage