From 1633233c9d8df7d5e4c53c078addcbfced017ae1 Mon Sep 17 00:00:00 2001 From: Mahdi Nayef Date: Sat, 27 May 2023 01:08:43 +0300 Subject: [PATCH] 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 --- .config/lf/lfrc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.config/lf/lfrc b/.config/lf/lfrc index d1c9402..25fb3d1 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -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 $lf -remote "send $id select \"$(fzf)\""