knowledge/tools/edit_record_sha1_p3
2025-04-07 13:38:00 +02:00

26 lines
593 B
Bash
Executable file

#!/bin/bash
[ "$#" -lt 3 ] && cat << EOT
Helper to edit a class record matching a particular dump-things collection.
Usage: $0 <record-base-path> <class> <record-pid>
EOT
[ "$#" -lt 3 ] && exit 1
set -e -u
editor="${EDITOR:=nano}"
base="$1"
class="$2"
pid="$3"
pid_encoded="$(printf '%s' "$pid" | sha1sum | cut -d ' ' -f1)"
dir="${base}/${class}/${pid_encoded:0:3}"
file_path="${dir}/${pid_encoded:3}.yaml"
mkdir -p "$dir"
# populate with pid already, if not yet existing
[ ! -e "$file_path" ] && printf 'pid: %s\n' "$pid" > "$file_path" || true
$editor "${dir}/${pid_encoded:3}.yaml"