From 1174c16b5d088919f4701d5ef12c3daa373b8338 Mon Sep 17 00:00:00 2001 From: Andre Ramnitz Date: Mon, 8 Jan 2024 22:44:20 +0100 Subject: [PATCH] lf: add bulk-rename function from this fine dude: https://github.com/gokcehan/lf/issues/149#issuecomment-470960434 --- config/lf/lfrc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/config/lf/lfrc b/config/lf/lfrc index 4a5ae92b..a376cd80 100644 --- a/config/lf/lfrc +++ b/config/lf/lfrc @@ -78,6 +78,35 @@ cmd zip ${{ rm -rf $1 }} +# add bulk-renaming of files +cmd bulk-rename ${{ + index=$(mktemp /tmp/lf-bulk-rename-index.XXXXXXXXXX) + if [ -n "${fs}" ]; then + echo "$fs" > $index + else + echo "$(ls "$(dirname $f)" | tr ' ' "\n")" > $index + fi + index_edit=$(mktemp /tmp/lf-bulk-rename.XXXXXXXXXX) + cat $index > $index_edit + $EDITOR $index_edit + if [ $(cat $index | wc -l) -eq $(cat $index_edit | wc -l) ]; then + max=$(($(cat $index | wc -l)+1)) + counter=1 + while [ $counter -le $max ]; do + a="$(cat $index | sed "${counter}q;d")" + b="$(cat $index_edit | sed "${counter}q;d")" + counter=$(($counter+1)) + + [ "$a" = "$b" ] && continue + [ -e "$b" ] && echo "File exists: $b" && continue + mv "$a" "$b" + done + else + echo "Number of lines must stay the same" + fi + rm $index $index_edit +}} + cmd on-select &{{ lf -remote "send $id set statfmt \"$(eza -ld --color=always "$f")\"" }} -- 2.51.2