From e4613cc238ce45e2bae4450c7b976312665c7cc5 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Thu, 21 Nov 2024 15:20:44 +0300 Subject: [PATCH] bin: Fix some re-encoding utilities --- bin/cleanup-recode.sh | 2 +- bin/cp_recode_fname | 5 +++-- bin/get_encodings | 1 - bin/recode-inplace | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/cleanup-recode.sh b/bin/cleanup-recode.sh index 4bf86d3..a957cbf 100755 --- a/bin/cleanup-recode.sh +++ b/bin/cleanup-recode.sh @@ -8,7 +8,7 @@ fi . get_encodings -for dir in "${filenames:-.}"; do +for dir in "${@:-.}"; do cleanup-filenames-recursive.sh "$dir" && recode-filenames-recursive.py -f "$from_encoding" -t "$to_encoding" \ "$dir" || exit 1 diff --git a/bin/cp_recode_fname b/bin/cp_recode_fname index 13fe8c2..ad7f7d0 100755 --- a/bin/cp_recode_fname +++ b/bin/cp_recode_fname @@ -12,12 +12,13 @@ case "$cmd" in esac . get_encodings -if [ -z "$filenames" ]; then + +if [ -z "$1" ]; then echo "Usage: $0 [-f from_encoding] [-t to_encoding] path [path ...]" >&2 exit 1 fi -for filename in "$filenames"; do +for filename in "$@"; do filename_recoded=`echo "$filename" | iconv -f "$from_encoding" -t "$to_encoding"` if [ "$filename_recoded" != "$filename" ]; then diff --git a/bin/get_encodings b/bin/get_encodings index 7327926..59c4be3 100755 --- a/bin/get_encodings +++ b/bin/get_encodings @@ -20,7 +20,6 @@ while getopts f:t: opt; do esac done shift `expr $OPTIND - 1` -filenames="$@" error() { echo "$@" >&2 diff --git a/bin/recode-inplace b/bin/recode-inplace index 91b629a..149b4ae 100755 --- a/bin/recode-inplace +++ b/bin/recode-inplace @@ -6,7 +6,7 @@ trap "exec rm -f $tmpfile" EXIT HUP INT QUIT PIPE TERM . get_encodings -for file in "$filenames"; do +for file in "$@"; do iconv -f "$from_encoding" -t "$to_encoding" "$file" >"$tmpfile" cp "$tmpfile" "$file" done -- 2.39.5