#!/bin/bash
# Copyright 2025 Florian Fischer

# Find Unterricht root
ROOT="${PWD/\/Unterricht\/*//Unterricht}"
if [ -z "${ROOT}" ]; then
	exit 1
fi

LESSON="$(realpath "${1:-"${PWD}"}")"
while read -r topic; do
	lesson="$(realpath "${topic}")"
	if [ "$(realpath "${lesson}")" = "${LESSON}" ]; then
		dirname "${topic}"
	fi
done <<< "$(find "${ROOT}" -type l -path "*_*/*topic*")"
