Add detector modules
This commit is contained in:
92
confsync/detectors/shell.py
Normal file
92
confsync/detectors/shell.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user