renamed 27002 EN versions

This commit is contained in:
Richard Kranendonk 2026-04-22 13:07:11 +02:00
parent 89f563a526
commit 5ac81f0efc

View file

@ -0,0 +1,60 @@
#!/usr/bin/env zsh
set -euo pipefail
execute=false
if [[ ${1:-} == '--execute' ]]; then
execute=true
shift
fi
if [[ $# -gt 0 ]]; then
print -u2 'Usage: rename-iso.zsh [--execute]'
exit 2
fi
# Requires Obsidian app running and CLI enabled.
# Adjust OBSIDIAN_CLI to the command you actually use (e.g. `obsidian`).
: ${OBSIDIAN_CLI:=obsidian}
files=(ISO_27002_2022_NL_*.md(N))
if (( ${#files} == 0 )); then
print 'No matching files found.'
exit 0
fi
for src in "$files[@]"; do
base=${src:t}
if [[ $base =~ '^ISO_27002_2022_NL_([0-9]+\.[0-9]+)_[A-Z]+ (.+)\.md$' ]]; then
version=${match[1]}
rest=${match[2]}
target="a-${version}-${rest}.md"
target=${target// /-}
target=${target//,}
target=${target//\(}
target=${target//\)}
target=${target//\'}
# Replace diacritics with base characters
target=${target//ï/i}
target=${target//é/e}
target=${target//è/e}
target=${target//ê/e}
target=${target//ë/e}
target=${target//ö/o}
target=${target//ü/u}
target=${target//ó/o}
target=${target//ô/o}
# Prevent double dashes
target=${target//--/-}
if [[ $src == $target ]]; then
print "SKIP $src"
continue
fi
print "SRC $src"
print "DEST $target"
if $execute; then
"$OBSIDIAN_CLI" rename file="$src" name="$target"
fi
else
print -u2 "WARN skipped (pattern mismatch): $src"
fi
done