From 4cd9c62c93acc26f8d560553b12738d8fdcaa361 Mon Sep 17 00:00:00 2001 From: mhdna Date: Wed, 24 May 2023 09:10:59 +0300 Subject: [PATCH] bulkrename using bult-ins instead of using a completely separate program --- .config/lf/lfrc | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.config/lf/lfrc b/.config/lf/lfrc index e3bace6d..9a251035 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -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 $lf -remote "send $id select \"$(fzf)\""