From c1e80055091b041d1e267db026641cddea074b02 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Wed, 4 Feb 2026 20:06:48 +0000 Subject: [PATCH] Add detector modules --- confsync/detectors/shell.py | 92 +++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 confsync/detectors/shell.py diff --git a/confsync/detectors/shell.py b/confsync/detectors/shell.py new file mode 100644 index 0000000..a380fc0 --- /dev/null +++ b/confsync/detectors/shell.py @@ -0,0 +1,92 @@ +"""Shell configuration file detectors.""" + +from pathlib import Path +from typing import List, TYPE_CHECKING + +from confsync.detectors.base import BaseDetector, detector +from confsync.models.config_models import ConfigCategory + +if TYPE_CHECKING: + from confsync.models.config_models import ConfigFile + + +@detector +class BashDetector(BaseDetector): + """Detector for Bash configurations.""" + + category = ConfigCategory.SHELL + tool_name = "bash" + + def get_default_locations(self) -> List[str]: + """Get Bash config locations.""" + return [ + str(Path.home() / ".bashrc"), + str(Path.home() / ".bash_profile"), + str(Path.home() / ".bash_logout"), + str(Path.home() / ".bash_history"), + ] + + def get_file_patterns(self) -> List[str]: + """Get Bash file patterns.""" + return [".bashrc", ".bash_profile", ".bash_logout", ".bash_history"] + + def detect(self) -> List["ConfigFile"]: + """Detect Bash configuration files.""" + configs = [] + home = Path.home() + + bash_files = [ + home / ".bashrc", + home / ".bash_profile", + home / ".bash_logout", + home / ".bash_history", + ] + + for bash_file in bash_files: + if bash_file.exists(): + config = self._create_config_file(str(bash_file)) + config.metadata = {"shell": "bash"} + configs.append(config) + + return configs + + +@detector +class ShellDetector(BaseDetector): + """Detector for generic shell configurations.""" + + category = ConfigCategory.SHELL + tool_name = "shell" + + def get_default_locations(self) -> List[str]: + """Get generic shell config locations.""" + return [ + str(Path.home() / ".profile"), + str(Path.home() / ".shrc"), + str(Path.home() / ".exports"), + str(Path.home() / ".aliases"), + ] + + def get_file_patterns(self) -> List[str]: + """Get shell file patterns.""" + return [".profile", ".shrc", ".exports", ".aliases", "profile"] + + def detect(self) -> List["ConfigFile"]: + """Detect generic shell configuration files.""" + configs = [] + home = Path.home() + + shell_files = [ + home / ".profile", + home / ".shrc", + home / ".exports", + home / ".aliases", + ] + + for shell_file in shell_files: + if shell_file.exists(): + config = self._create_config_file(str(shell_file)) + config.metadata = {"shell": "generic"} + configs.append(config) + + return configs