From 94114d7dd5346bfda8ce347094358c6f84fe109d Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 22 Mar 2026 18:15:34 +0000 Subject: [PATCH] Initial upload: shell-history-semantic-search v0.1.0 --- src/shell_history_search/parsers/bash.py | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/shell_history_search/parsers/bash.py diff --git a/src/shell_history_search/parsers/bash.py b/src/shell_history_search/parsers/bash.py new file mode 100644 index 0000000..3359f32 --- /dev/null +++ b/src/shell_history_search/parsers/bash.py @@ -0,0 +1,39 @@ +from pathlib import Path +from typing import Iterator +import re + +from shell_history_search.parsers import HistoryEntry, HistoryParser + + +class BashHistoryParser(HistoryParser): + shell_type = "bash" + + def get_history_path(self) -> Path: + return Path.home() / ".bash_history" + + def parse(self, history_path: Path) -> Iterator[HistoryEntry]: + timestamp_pattern = re.compile(r"^#(\d{10,})$") + + for line in self.read_history_file(history_path): + line = line.strip() + if not line: + continue + + if line.startswith("#"): + continue + + timestamp_match = timestamp_pattern.match(line) + if timestamp_match: + continue + + if line.startswith(" "): + continue + + entry = HistoryEntry( + command=line, + shell_type=self.shell_type, + timestamp=None, + hostname=None, + command_hash=HistoryEntry.create_hash(line), + ) + yield entry \ No newline at end of file