From b137da0fa0afabb505cd01d97e582e2323b77a7f Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 1 Feb 2026 08:51:35 +0000 Subject: [PATCH] Initial upload: Shell History Alias Generator with full test suite --- shell_alias_gen/parsers/bash.py | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 shell_alias_gen/parsers/bash.py diff --git a/shell_alias_gen/parsers/bash.py b/shell_alias_gen/parsers/bash.py new file mode 100644 index 0000000..58dd627 --- /dev/null +++ b/shell_alias_gen/parsers/bash.py @@ -0,0 +1,41 @@ +"""Bash history parser.""" + +import os +from datetime import datetime +from typing import List, Optional + +from .base import HistoryParser, ParsedCommand + + +class BashHistoryParser(HistoryParser): + """Parser for Bash history files.""" + + SHELL_NAME = "bash" + DEFAULT_HISTORY_FILE = os.path.expanduser("~/.bash_history") + + def parse_file(self, filepath: str) -> List[ParsedCommand]: + """Parse a bash history file.""" + try: + with open(filepath, 'r', encoding='utf-8', errors='replace') as f: + content = f.read() + return self.parse_content(content) + except FileNotFoundError: + return [] + except Exception: + return [] + + def parse_content(self, content: str) -> List[ParsedCommand]: + """Parse bash history content from a string.""" + commands = [] + lines = content.splitlines() + + for line_num, line in enumerate(lines, start=1): + line = line.rstrip('\n\r') + if line and not line.startswith('#'): + cmd = ParsedCommand( + raw_command=line, + line_number=line_num + ) + commands.append(cmd) + + return commands