summaryrefslogtreecommitdiff
path: root/scripts/virename
blob: 8c30ccfe2ef3d1121b577d78148beef3bbd63936 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 -r f; do
		fold=$(echo "$f" | sed 's/	.*//')
		fnew=$(echo "$f" | sed 's/.*	//')
		if [ "$fold" != "$fnew" ]; then
			mv "$fold" "$fnew" \
			|| echo "Error renaming $fold to $fnew"
		fi
	done
fi

Generated with cgit - Back to sebastiano.tronto.net