commit 926f38a941da5f917971e609f0c03d9b69c92535
parent ca5cf90979678c2c04ac78c4bfbc7ff5ef444f82
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sun, 6 Mar 2022 12:41:06 +0100
Added virename
Diffstat:
3 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -34,6 +34,7 @@ SCRIPTS = addressgrep \
translate \
trash \
urlgrep \
+ virename \
volume \
websearch \
xedit \
diff --git a/sel b/sel
@@ -17,6 +17,8 @@
# TODO: add possibility of specifying file.
# TODO 2: The usage of paste(1) is a bit of a hack, and for example it does
# not work if filenames contain tab characters. Fix this.
+# Bug (probably not fixing this, use virename): moving moving a file to
+# itself gives an error and rm is not run.
file="$XDG_DATA_HOME/selectedfiles"
menu=${MENU:-dmenu}
diff --git a/virename b/virename
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# Rename all files in the current directory with a visual editor.
+# Similar to sel add all && sel mv, but it actually works.
+
+file=$(mktemp)
+file2=$(mktemp)
+editor=${EDITOR:-vi}
+
+ls | tee "$file" > "$file2"
+$editor "$file2"
+
+if [ "$(wc -l $file | awk '{print $1}')" != \
+ "$(wc -l $file2 | awk '{print $1}')" ]; then
+ echo "Error reading new file names"
+else
+ paste "$file" "$file2" | while read f; do
+ fold=$(echo "$f" | sed 's/\t.*//')
+ fnew=$(echo "$f" | sed 's/.*\t//')
+ if [ "$fold" != "$fnew" ]; then
+ mv "$fold" "$fnew" \
+ || echo "Error renaming $fold to $fnew"
+ fi
+ done
+fi