diff options
| author | Marc Vertes <mvertes@free.fr> | 2021-06-20 16:50:57 +0200 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2021-06-20 16:50:57 +0200 |
| commit | c54b5ef0f166a6454522686e6a2a5c1550505eb0 (patch) | |
| tree | f438edbbf48edb1e9f7df645666936771d37d8c0 /bin/vimki | |
| parent | c151c4ee62bd7b045a98dbcf3f1d6537948ba0d0 (diff) | |
update
Diffstat (limited to 'bin/vimki')
| -rwxr-xr-x | bin/vimki | 33 |
1 files changed, 26 insertions, 7 deletions
@@ -4,14 +4,33 @@ # rename changes the link name and propagates the change in the wiki rename1() { + [ "$(head -c 8 "$3")" = VimCrypt ] && return gawk -v old="$1" -v new="$2" -v IGNORECASE=1 ' { gsub("[[]" old "[]]", "[" new "]") print } - ' "$3" + ' "$3" > "$3.$$" && mv "$3.$$" "$3" } +link2rx() { + gawk -v rx="$1" -v IGNORECASE=1 ' + BEGIN { + 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) + print rx + }' +} + +#shellcheck disable=SC2020 + linkfile() { echo "$1" | tr '[:upper:]' '[:lower:]' | @@ -20,11 +39,11 @@ linkfile() { } rename() { - for f in *; do - rename1 "$1" "$2" "$f" > "$f.$$" && mv "$f.$$" "$f" - done - oldf="$(linkfile "$1")" - [ -f "$oldf" ] && mv "$oldf" "$(linkfile "$2")" + rx=$(link2rx "$1") + # Parallelize renaming + echo *.md | xargs -n 1 -P 8 "$0" rename1 "$rx" "$2" + oldf="$(linkfile "$1").md" + [ -f "$oldf" ] && mv "$oldf" "$(linkfile "$2").md" } fixfiles() { @@ -33,5 +52,5 @@ fixfiles() { done } -cd ~/Wiki +cd ~/Wiki || exit "$@" |
