-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbulkrename.tool
More file actions
executable file
·41 lines (30 loc) · 848 Bytes
/
bulkrename.tool
File metadata and controls
executable file
·41 lines (30 loc) · 848 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh
# rename files in your `$EDITOR` (by [Mendes](https://github.com/mendess/))
from="$(mktemp)"
to="$(mktemp)"
trap 'rm $from $to' 0 1 2 3 6 14 15
echo "# use # to skip renaming a file" > "$from"
find ./* -maxdepth 0 | sed 's|./||g' >> "$from"
cp "$from" "$to"
if [ "$EDITOR" ]; then
ed="$EDITOR"
elif [ "$VISUAL" ]; then
ed="$VISUAL"
else
ed=vim
fi
"$ed" "$to"
python -c "from sys import argv
import subprocess
with open('$from', 'r') as f:
f1 = [l.strip() for l in f]
with open('$to', 'r') as f:
f2 = [l.strip() for l in f]
filt = lambda x: x[0] != x[1] and not x[1].startswith('#')
for l1, l2 in filter(filt, zip(f1, f2)):
print(f\"mv -vi '{l1}' '{l2}'\")
c = input('Confirm [Y/n] ')
if c != 'n' and c != 'N':
for l1, l2 in filter(filt, zip(f1, f2)):
subprocess.run(['mv', '-vi', l1, l2])
"