ollie/tools/memory_recall

29 lines
597 B
Bash
Executable File

#!/usr/bin/env bash
# description: Search memories by keyword, tag, or title
# Args: <query>
[ -z "$*" ] && echo "error: query is required" && exit 1
mem_dir="${OLLIE_MEMORY_PATH:-$HOME/.local/share/ollie/memory}"
if [ ! -d "$mem_dir" ]; then
echo "no memories found"
exit 0
fi
query="$*"
# Search filenames (title/tag match) and file bodies
matches=$(grep -ril "$query" "$mem_dir" 2>/dev/null)
if [ -z "$matches" ]; then
echo "no matches for: $query"
exit 0
fi
while IFS= read -r file; do
echo "=== $(basename "$file") ==="
cat "$file"
echo
done <<< "$matches"