From: Andre Ramnitz Date: Mon, 8 Jan 2024 21:44:20 +0000 (+0100) Subject: lf: add bulk-rename function X-Git-Tag: v0.2~242 X-Git-Url: https://git.ramnitz.eu/?a=commitdiff_plain;h=1174c16b5d088919f4701d5ef12c3daa373b8338;p=dotfiles.git lf: add bulk-rename function from this fine dude: https://github.com/gokcehan/lf/issues/149#issuecomment-470960434 --- 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")\"" }}