-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbulkrename.spell
More file actions
executable file
·42 lines (31 loc) · 894 Bytes
/
Copy pathbulkrename.spell
File metadata and controls
executable file
·42 lines (31 loc) · 894 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
42
#!/bin/sh
# Bulk rename every file in the current directory using your default editor
# (Editor defined by $EDITOR or $VISUAL)
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])
"