summaryrefslogtreecommitdiff
path: root/bin/vimki
blob: af5c58ce60c413e6bd0110f198cd87bff455d0c0 (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
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh

# Batch operations on vimki

# rename changes the link name and propagates the change in the wiki
rename1() {
	gawk -v old="$1" -v new="$2" -v IGNORECASE=1 '
	{
		gsub("[[]" old "[]]", "[" new "]")
		print
	}
	' "$3"
}

linkfile() {
	echo "$1" |
	tr '[:upper:]' '[:lower:]' |
	tr 'åäáàâãçéèêëîíìïôöóõòùûüúÿñ' 'aaaaaaceeeeiiiiooooouuuuyn' |
	awk '{gsub(/\W+/, "_"); print}'
}

rename() {
	for f in *; do
		rename1 "$1" "$2" "$f" > "$f.$$" && mv "$f.$$" "$f"
	done
	oldf="$(linkfile "$1")"
	[ -f "$oldf" ] && mv "$oldf" "$(linkfile "$2")"
}

fixfiles() {
	for f in *; do
		mv "$f" "$(linkfile "$f")"
	done
}

cd ~/Wiki
"$@"