Initial commit
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
# Find backlinks (notes containing [[note-name]]) within a configured vault.
|
||||
#
|
||||
# Usage: vault_backlinks.sh <note-name> [vault-name]
|
||||
#
|
||||
# The vault path always comes from
|
||||
# ~/.agent-skills/obsidian-vault-kb/config.json — never from a raw argument.
|
||||
|
||||
set -euo pipefail
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=_lib.sh
|
||||
source "$SCRIPT_DIR/_lib.sh"
|
||||
|
||||
NOTE_NAME="${1:?Usage: vault_backlinks.sh <note-name> [vault-name]}"
|
||||
VAULT_NAME="${2:-}"
|
||||
|
||||
VAULT_RAW="$(resolve_vault_path "$VAULT_NAME")"
|
||||
VAULT="$(canonicalize_and_check_dir "$VAULT_RAW")"
|
||||
|
||||
# Build a regex-safe literal for the note name (escape regex metachars).
|
||||
ESCAPED_NAME=$(printf '%s' "$NOTE_NAME" | sed -e 's/[.[\*^$/]/\\&/g')
|
||||
|
||||
echo "== Notes linking to [[$NOTE_NAME]] in $VAULT =="
|
||||
echo
|
||||
|
||||
if command -v rg >/dev/null 2>&1; then
|
||||
rg -n "\[\[${ESCAPED_NAME}(\||\]\])" "$VAULT" \
|
||||
-g '!.obsidian' -g '!.git' -g '*.md' || echo "(no backlinks found)"
|
||||
else
|
||||
grep -rn "\[\[${ESCAPED_NAME}" "$VAULT" --include='*.md' 2>/dev/null || echo "(no backlinks found)"
|
||||
fi
|
||||
Reference in New Issue
Block a user