37 lines
1.0 KiB
Bash
Executable File
37 lines
1.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# search.sh — grep-based wiki search helper
|
|
# Usage: bash tools/search.sh "query term"
|
|
# Run from wiki vault root directory
|
|
|
|
QUERY="$1"
|
|
WIKI_DIR="${2:-wiki}"
|
|
|
|
if [ -z "$QUERY" ]; then
|
|
echo "Usage: bash tools/search.sh \"query term\" [wiki-dir]"
|
|
exit 1
|
|
fi
|
|
|
|
echo "=== Searching wiki for: \"$QUERY\" ==="
|
|
echo ""
|
|
|
|
# Title matches (highest priority)
|
|
echo "--- Title matches ---"
|
|
grep -ril "^title:.*$QUERY" "$WIKI_DIR" --include="*.md" | while read -r f; do
|
|
title=$(grep "^title:" "$f" | head -1 | sed 's/title: "//' | sed 's/"//')
|
|
echo " $f ($title)"
|
|
done
|
|
|
|
echo ""
|
|
|
|
# Content matches
|
|
echo "--- Content matches ---"
|
|
grep -rn "$QUERY" "$WIKI_DIR" --include="*.md" -i | grep -v "^Binary" | while IFS=: read -r file line content; do
|
|
# Skip frontmatter lines
|
|
if echo "$content" | grep -qv "^---\|^title:\|^date:\|^type:\|^tags:"; then
|
|
echo " $file:$line → $(echo "$content" | sed 's/^[[:space:]]*//' | cut -c1-80)"
|
|
fi
|
|
done | head -30
|
|
|
|
echo ""
|
|
echo "=== Tip: open these in Obsidian for full context and graph view ==="
|