diff --git a/Corpus/Standards/ISO-27002-OST/ISO27002-NL-2022/rename-iso.zsh b/Corpus/Standards/ISO-27002-OST/ISO27002-NL-2022/rename-iso.zsh new file mode 100755 index 0000000..65e34f4 --- /dev/null +++ b/Corpus/Standards/ISO-27002-OST/ISO27002-NL-2022/rename-iso.zsh @@ -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