bulkrename using built-ins instead of using a completely separate program (#1330)

* bulkrename using bult-ins instead of using a completely separate program

* Make it more efficient
This commit is contained in:
Mahdi Nayef 2023-05-27 01:08:43 +03:00 committed by GitHub
parent ce1f0bfa05
commit 1633233c9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -93,7 +93,27 @@ cmd copyto ${{
}}
cmd setbg "$1"
cmd bulkrename $vidir
cmd bulkrename ${{
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 -f "$tmpfile_old" "$tmpfile_new"
lf -remote "send $id unselect"
}}
# Bindings
map <c-f> $lf -remote "send $id select \"$(fzf)\""