Add detector modules
This commit is contained in:
164
confsync/detectors/terminal.py
Normal file
164
confsync/detectors/terminal.py
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
"""Terminal 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 ZshDetector(BaseDetector):
|
||||||
|
"""Detector for Zsh configurations."""
|
||||||
|
|
||||||
|
category = ConfigCategory.TERMINAL
|
||||||
|
tool_name = "zsh"
|
||||||
|
|
||||||
|
def get_default_locations(self) -> List[str]:
|
||||||
|
"""Get Zsh config locations."""
|
||||||
|
return [
|
||||||
|
str(Path.home() / ".zshrc"),
|
||||||
|
str(Path.home() / ".zshenv"),
|
||||||
|
str(Path.home() / ".zprofile"),
|
||||||
|
str(Path.home() / ".zlogin"),
|
||||||
|
str(Path.home() / ".zlogout"),
|
||||||
|
str(Path.home() / ".oh-my-zsh"),
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_file_patterns(self) -> List[str]:
|
||||||
|
"""Get Zsh file patterns."""
|
||||||
|
return [".zshrc", ".zshenv", ".zprofile", ".zlogin", ".zlogout"]
|
||||||
|
|
||||||
|
def detect(self) -> List["ConfigFile"]:
|
||||||
|
"""Detect Zsh configuration files."""
|
||||||
|
configs = []
|
||||||
|
home = Path.home()
|
||||||
|
|
||||||
|
zsh_files = [
|
||||||
|
home / ".zshrc",
|
||||||
|
home / ".zshenv",
|
||||||
|
home / ".zprofile",
|
||||||
|
home / ".zlogin",
|
||||||
|
home / ".zlogout",
|
||||||
|
]
|
||||||
|
|
||||||
|
for zsh_file in zsh_files:
|
||||||
|
if zsh_file.exists():
|
||||||
|
config = self._create_config_file(str(zsh_file))
|
||||||
|
config.metadata = {"shell": "zsh"}
|
||||||
|
configs.append(config)
|
||||||
|
|
||||||
|
oh_my_zsh = home / ".oh-my-zsh"
|
||||||
|
if oh_my_zsh.exists() and oh_my_zsh.is_dir():
|
||||||
|
oh_my_zsh_files = [
|
||||||
|
oh_my_zsh / "custom" / "example.zsh",
|
||||||
|
]
|
||||||
|
for omz_file in oh_my_zsh_files:
|
||||||
|
if omz_file.exists():
|
||||||
|
config = self._create_config_file(str(omz_file))
|
||||||
|
config.metadata = {"shell": "zsh", "oh-my-zsh": True}
|
||||||
|
configs.append(config)
|
||||||
|
|
||||||
|
return configs
|
||||||
|
|
||||||
|
|
||||||
|
@detector
|
||||||
|
class FishDetector(BaseDetector):
|
||||||
|
"""Detector for Fish shell configurations."""
|
||||||
|
|
||||||
|
category = ConfigCategory.TERMINAL
|
||||||
|
tool_name = "fish"
|
||||||
|
|
||||||
|
def get_default_locations(self) -> List[str]:
|
||||||
|
"""Get Fish config locations."""
|
||||||
|
return [
|
||||||
|
str(Path.home() / ".config" / "fish"),
|
||||||
|
str(Path.home() / ".fishrc"),
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_file_patterns(self) -> List[str]:
|
||||||
|
"""Get Fish file patterns."""
|
||||||
|
return ["config.fish", "fishfile"]
|
||||||
|
|
||||||
|
def detect(self) -> List["ConfigFile"]:
|
||||||
|
"""Detect Fish configuration files."""
|
||||||
|
configs = []
|
||||||
|
home = Path.home()
|
||||||
|
|
||||||
|
fish_config_dir = home / ".config" / "fish"
|
||||||
|
if fish_config_dir.exists() and fish_config_dir.is_dir():
|
||||||
|
fish_files = [
|
||||||
|
fish_config_dir / "config.fish",
|
||||||
|
fish_config_dir / "fishfile",
|
||||||
|
fish_config_dir / "functions",
|
||||||
|
]
|
||||||
|
|
||||||
|
for fish_file in fish_files:
|
||||||
|
if fish_file.exists():
|
||||||
|
if fish_file.is_file():
|
||||||
|
config = self._create_config_file(str(fish_file))
|
||||||
|
config.metadata = {"shell": "fish"}
|
||||||
|
configs.append(config)
|
||||||
|
elif fish_file.is_dir():
|
||||||
|
for subfile in fish_file.iterdir():
|
||||||
|
if subfile.is_file():
|
||||||
|
config = self._create_config_file(str(subfile))
|
||||||
|
config.metadata = {"shell": "fish", "subdirectory": "functions"}
|
||||||
|
configs.append(config)
|
||||||
|
|
||||||
|
fishrc = home / ".fishrc"
|
||||||
|
if fishrc.exists():
|
||||||
|
config = self._create_config_file(str(fishrc))
|
||||||
|
config.metadata = {"shell": "fish"}
|
||||||
|
configs.append(config)
|
||||||
|
|
||||||
|
return configs
|
||||||
|
|
||||||
|
|
||||||
|
@detector
|
||||||
|
class TmuxDetector(BaseDetector):
|
||||||
|
"""Detector for Tmux configurations."""
|
||||||
|
|
||||||
|
category = ConfigCategory.TMUX
|
||||||
|
tool_name = "tmux"
|
||||||
|
|
||||||
|
def get_default_locations(self) -> List[str]:
|
||||||
|
"""Get Tmux config locations."""
|
||||||
|
return [
|
||||||
|
str(Path.home() / ".tmux.conf"),
|
||||||
|
str(Path.home() / ".tmux.conf.local"),
|
||||||
|
str(Path.home() / ".config" / "tmux"),
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_file_patterns(self) -> List[str]:
|
||||||
|
"""Get Tmux file patterns."""
|
||||||
|
return [".tmux.conf", ".tmux.conf.local", "tmux.conf"]
|
||||||
|
|
||||||
|
def detect(self) -> List["ConfigFile"]:
|
||||||
|
"""Detect Tmux configuration files."""
|
||||||
|
configs = []
|
||||||
|
home = Path.home()
|
||||||
|
|
||||||
|
tmux_files = [
|
||||||
|
home / ".tmux.conf",
|
||||||
|
home / ".tmux.conf.local",
|
||||||
|
]
|
||||||
|
|
||||||
|
for tmux_file in tmux_files:
|
||||||
|
if tmux_file.exists():
|
||||||
|
config = self._create_config_file(str(tmux_file))
|
||||||
|
config.metadata = {"terminal_multiplexer": "tmux"}
|
||||||
|
configs.append(config)
|
||||||
|
|
||||||
|
tmux_config_dir = home / ".config" / "tmux"
|
||||||
|
if tmux_config_dir.exists() and tmux_config_dir.is_dir():
|
||||||
|
for file_path in tmux_config_dir.iterdir():
|
||||||
|
if file_path.is_file():
|
||||||
|
config = self._create_config_file(str(file_path))
|
||||||
|
config.metadata = {"terminal_multiplexer": "tmux"}
|
||||||
|
configs.append(config)
|
||||||
|
|
||||||
|
return configs
|
||||||
Reference in New Issue
Block a user