#!/usr/bin/env bash # Quick structured overview of a configured Obsidian vault: # folder structure, note count per folder, frontmatter tags in use. # # Usage: vault_index.sh [vault-name] # vault-name is optional if only one vault is configured. # The path is always resolved from ~/.agent-skills/obsidian-vault-kb/config.json — # this script never accepts a raw filesystem path as an argument. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=_lib.sh source "$SCRIPT_DIR/_lib.sh" VAULT_NAME="${1:-}" VAULT_RAW="$(resolve_vault_path "$VAULT_NAME")" VAULT="$(canonicalize_and_check_dir "$VAULT_RAW")" echo "== Vault: $VAULT ==" echo echo "== Folder structure ==" find "$VAULT" -type d \ -not -path '*/.obsidian*' -not -path '*/.git*' \ | sed "s|^$VAULT||" | sort echo echo "== Notes per top-level folder ==" find "$VAULT" -mindepth 1 -maxdepth 1 -type d \ -not -name '.obsidian' -not -name '.git' \ | while read -r dir; do count=$(find "$dir" -name '*.md' | wc -l) echo "$(basename "$dir"): $count" done echo echo "== Frontmatter tags (field 'tags:') ==" if command -v rg >/dev/null 2>&1; then rg -o --no-filename '^tags:\s*\[?([^]]*)\]?' -r '$1' "$VAULT" 2>/dev/null \ | tr ',' '\n' | sed 's/^\s*-\?\s*//; s/\s*$//' | sort -u | grep -v '^$' || true else grep -rho '^tags:.*' "$VAULT" --include='*.md' 2>/dev/null | sort -u || true fi echo echo "== Possible index/MOC files ==" find "$VAULT" -iname '*index*.md' -o -iname '*moc*.md' -o -iname '*overview*.md' 2>/dev/null || true