From: Oleg Broytman Date: Thu, 21 Nov 2024 12:20:44 +0000 (+0300) Subject: bin: Fix some re-encoding utilities X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;p=dotfiles.git bin: Fix some re-encoding utilities --- 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