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

This commit is contained in:
mhdna 2023-05-24 09:10:59 +03:00
parent 991b052a55
commit 4cd9c62c93

View File

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