From f8f2cea5e95873a217ea4a29f449acc402376e14 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 1 Feb 2026 08:51:38 +0000 Subject: [PATCH] Initial upload: Shell History Alias Generator with full test suite --- shell_alias_gen/parsers/history_factory.py | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 shell_alias_gen/parsers/history_factory.py diff --git a/shell_alias_gen/parsers/history_factory.py b/shell_alias_gen/parsers/history_factory.py new file mode 100644 index 0000000..7d176ee --- /dev/null +++ b/shell_alias_gen/parsers/history_factory.py @@ -0,0 +1,46 @@ +"""History parser factory for creating shell-specific parsers.""" + +from typing import Dict, Optional, Type +from .base import HistoryParser +from .bash import BashHistoryParser +from .zsh import ZshHistoryParser +from .fish import FishHistoryParser + + +class HistoryParserFactory: + """Factory for creating shell-specific history parsers.""" + + _parsers: Dict[str, Type[HistoryParser]] = { + 'bash': BashHistoryParser, + 'zsh': ZshHistoryParser, + 'fish': FishHistoryParser, + } + + @classmethod + def get_parser(cls, shell_type: str) -> Optional[HistoryParser]: + """Get a parser instance for the specified shell type.""" + parser_class = cls._parsers.get(shell_type.lower()) + if parser_class: + return parser_class() + return None + + @classmethod + def register_parser(cls, name: str, parser_class: Type[HistoryParser]) -> None: + """Register a new parser class.""" + cls._parsers[name.lower()] = parser_class + + @classmethod + def get_supported_shells(cls) -> list: + """Return list of supported shell types.""" + return list(cls._parsers.keys()) + + @classmethod + def detect_shell_from_file(cls, filepath: str) -> Optional[str]: + """Try to detect shell type from file extension or content.""" + if filepath.endswith('.json'): + return 'fish' + elif filepath.endswith('.zsh_history'): + return 'zsh' + elif filepath.endswith('.bash_history'): + return 'bash' + return None