Make it more efficient

This commit is contained in:
Mahdi Nayef 2023-05-26 10:09:33 +00:00 committed by GitHub
parent 4cd9c62c93
commit 13714818d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,22 +95,23 @@ cmd copyto ${{
cmd setbg "$1"
cmd bulkrename ${{
old="$(mktemp)"
new="$(mktemp)"
[ -z "$fs" ] && fs="$(ls)"
printf '%s\n' "$fs" >"$old"
printf '%s\n' "$fs" >"$new"
$EDITOR "$new"
[ "$(wc -l < "$new")" -ne "$(wc -l < "$old")" ] && exit
paste "$old" "$new" | while IFS= read -r names; do
src="$(printf '%s' "$names" | cut -f1)"
dst="$(printf '%s' "$names" | cut -f2)"
if [ "$src" = "$dst" ] || [ -e "$dst" ]; then
continue
fi
mv -- "$src" "$dst"
tmpfile_old="$(mktemp)"
tmpfile_new="$(mktemp)"
[ -n "$fs" ] && fs=$(basename -a $fs) || fs=$(ls)
echo "$fs" > "$tmpfile_old"
echo "$fs" > "$tmpfile_new"
$EDITOR "$tmpfile_new"
[ "$(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
rm -- "$old" "$new"
rm -f "$tmpfile_old" "$tmpfile_new"
lf -remote "send $id unselect"
}}