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
43
44
45
46
47
48
49
50
|
#!/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 '
BEGIN {
rx = old
gsub(/_/, "\\W+", rx)
gsub(/a/, "[aåäáàâã]", rx)
gsub(/c/, "[cç]", rx)
gsub(/e/, "[eéèêë]", rx)
gsub(/i/, "[iîíìï]", rx)
gsub(/o/, "[oôöóõò]", rx)
gsub(/u/, "[uùûüú]", rx)
gsub(/y/, "[yÿ]", rx)
gsub(/n/, "[nñ]", rx)
}
{
gsub("[[]" rx "[]]", "[" new "]")
print
}
' "$3"
}
linkfile() {
echo "$1" |
tr '[:upper:]' '[:lower:]' |
tr 'åäáàâãçéèêëîíìïôöóõòùûüúÿñ' 'aaaaaaceeeeiiiiooooouuuuyn' |
awk '{gsub(/\W+/, "_"); print}'
}
rename() {
for f in *.md; do
[ "$(head -c 8 "$f")" = VimCrypt ] && continue
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
"$@"
|