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