#!/bin/bash # Copyright Cédric Picard 2014 -- License WTFPL # Inspired by Ranger's -- See https://github.com/hut/ranger set -e -u if [ $# -ne 0 ] ; then { for i in "$@" ; do printf "$i\n" ; done } | "$0" exit fi [ -x "$(which "$EDITOR" 2>/dev/null)" ] || EDITOR='vi' file=/tmp/blkrn-$$ cat > ${file}.1 exec /dev/tty cp ${file}.1 ${file}.2 "$EDITOR" ${file}.2 if [ $(wc -l < ${file}.1) -ne $(wc -l < ${file}.2) ] ; then rm ${file}.1 ${file}.2 echo "Wrong number of lines" >&2 exit 1 fi sed -i "s/'/'\"'\"'/g" ${file}.1 ${file}.2 paste -d "\n" ${file}.1 ${file}.2 | while read -r input ; do read -r output if [ "$input" != "$output" ] ; then echo "mv -- '$input' '$output'" fi done > ${file}.sh if [ "$(stat --printf="%s" ${file}.sh)" -ne 0 ] ; then "$EDITOR" ${file}.sh sh ${file}.sh fi rm ${file}.1 ${file}.2 ${file}.sh