krz/crumb
clone: git clone https://gitbay.org/krz/crumb.git
main: search.py · raw
1import os
2import sys
3
4LOG_PATH = os.path.expanduser("~/.crumb/history.org")
5
6
7def search_log(query):
8 """
9 Search for a given query string within the crumb history log file and print matching entries.
10
11 Args:
12 query (str): The search term to look for in the history entries.
13
14 Returns:
15 None
16 """
17 if not os.path.exists(LOG_PATH):
18 print("No history file found.")
19 return
20
21 with open(LOG_PATH, "r") as f:
22 entries = f.read().split("* ")[1:]
23
24 found = 0
25 for entry in entries:
26 if query.lower() in entry.lower():
27 print(f"* {entry.strip()}\n")
28 found += 1
29
30 if found == 0:
31 print("No matches found.")
32
33
34if __name__ == "__main__":
35 """
36 Entry point for the script. Parses command line arguments and calls the search function.
37 Usage: search.py <search term>
38 """
39 if len(sys.argv) < 2:
40 print("Usage: search.py <search term>")
41 else:
42 search_log(sys.argv[1])