diff options
| author | Marc Vertes <mvertes@free.fr> | 2021-06-20 15:36:38 +0200 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2021-06-20 15:36:38 +0200 |
| commit | 0ad6087640b7c6f9bee6e954f0736d9c183f6a5c (patch) | |
| tree | db43b025d18f03456096e12263c812f4299d8786 /bin/vimki | |
| parent | 1433c15716d0da97d54d39f7397b80654ce10415 (diff) | |
vimki: parallelize rename
Diffstat (limited to 'bin/vimki')
| -rwxr-xr-x | bin/vimki | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -4,12 +4,13 @@ # 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() { @@ -39,10 +40,8 @@ linkfile() { rename() { rx=$(link2rx "$1") - for f in *.md; do - [ "$(head -c 8 "$f")" = VimCrypt ] && continue - rename1 "$rx" "$2" "$f" > "$f.$$" && mv "$f.$$" "$f" - done + # Parallelize renaming + echo *.md | xargs -n 1 -P 8 "$0" rename1 "$rx" "$2" oldf="$(linkfile "$1").md" [ -f "$oldf" ] && mv "$oldf" "$(linkfile "$2").md" } |
