dotfiles/bin/br

27 lines
499 B
Bash
Executable File

#!/bin/sh
# batch replace: echo file1\nfile2 | br <REGEX> <NEWSTR>
# rule 1: use single quote '
# rule 2: //// for literal /
set -e
FILES=$(awk '{print}')
COL=$(tput cols)
PAT=$1
STR=$2
export COL PAT STR
echo "$FILES" | while IFS= read -r FILE; do
fr "$FILE"
done | less
printf "Are you sure [y/N]? "
read -r YN < /dev/tty
if [ "$YN" = 'y' ]; then
echo "$FILES" | while IFS= read -r FILE; do
TMP=$(mktemp)
REP=1 fr "$FILE" > "$TMP"
mv "$TMP" "$FILE"
done
fi