Merge b157d54410b152095f6475e8df3fcdb16207aad8 into 7a96fb100cf385e05c211937b509d2bf166299e6

This commit is contained in:
Emre AKYÜZ 2023-12-30 10:47:12 -07:00 committed by GitHub
commit a8dd63becf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -112,21 +112,29 @@ cmd setbg "$1"
cmd bulkrename ${{ cmd bulkrename ${{
tmpfile_old="$(mktemp)" tmpfile_old="$(mktemp)"
tmpfile_new="$(mktemp)" tmpfile_new="$(mktemp)"
tmpfile_ext="$(mktemp)"
[ -n "$fs" ] && fs=$(basename -a $fs) || fs=$(ls) [ -n "$fs" ] && fs=$(basename -a $fs | sort -fV) || fs=$(find . -maxdepth 1 -type f | cut -c 3- | sort -fV)
echo "$fs" > "$tmpfile_old" for f in $fs; do
echo "$fs" > "$tmpfile_new" echo "${f%.*}" >> "$tmpfile_old"
$EDITOR "$tmpfile_new" echo "${f##*.}" >> "$tmpfile_ext"
[ "$(wc -l < "$tmpfile_old")" -eq "$(wc -l < "$tmpfile_new")" ] || { rm -f "$tmpfile_old" "$tmpfile_new"; exit 1; }
paste "$tmpfile_old" "$tmpfile_new" | while IFS="$(printf '\t')" read -r src dst
do
[ "$src" = "$dst" ] || [ -e "$dst" ] || mv -- "$src" "$dst"
done done
rm -f "$tmpfile_old" "$tmpfile_new" cp "$tmpfile_old" "$tmpfile_new"
$EDITOR "$tmpfile_new"
[ "$(wc -l < "$tmpfile_old")" -eq "$(wc -l < "$tmpfile_new")" ] || { rm -f "$tmpfile_old" "$tmpfile_new" "$tmpfile_ext"; exit 1; }
exec 3<"$tmpfile_old"
exec 4<"$tmpfile_ext"
exec 5<"$tmpfile_new"
while IFS= read -r old_name <&3 && IFS= read -r ext <&4 && IFS= read -r new_name <&5; do
[ "$old_name" = "$new_name" ] || [ -e "$new_name.$ext" ] || mv -- "$old_name.$ext" "$new_name.$ext"
done
rm -f "$tmpfile_old" "$tmpfile_new" "$tmpfile_ext"
lf -remote "send $id unselect" lf -remote "send $id unselect"
}} }}