diff --git a/src/autoclaude/cli.py b/src/autoclaude/cli.py index 4b94e0b..846d22d 100644 --- a/src/autoclaude/cli.py +++ b/src/autoclaude/cli.py @@ -462,11 +462,42 @@ class ClaudeCLI: content = tmux_conf.read_text() - # Check if already configured + # Check if already configured for autoclaude if 'autoclaude-toggle' in content: self.print_info("Shortcut already configured in ~/.tmux.conf") return + # Check if 'bind a' is already used by something else + import re + if re.search(r'^\s*bind\s+a\s+', content, re.MULTILINE): + self.print_warning("The key 'a' is already bound in your tmux config") + self.print_info("Current binding:") + for line in content.split('\n'): + if re.search(r'^\s*bind\s+a\s+', line): + print(f" {line.strip()}") + print() + self.print_info("Options:") + print(" 1. Replace the existing binding") + print(" 2. Use a different key") + print(" 3. Cancel installation") + choice = input(f"\n{Colors.BOLD}Choose option (1-3): {Colors.ENDC}") + + if choice == '1': + # Remove existing 'bind a' line + lines = content.split('\n') + lines = [l for l in lines if not re.search(r'^\s*bind\s+a\s+', l)] + content = '\n'.join(lines) + elif choice == '2': + key = input(f"{Colors.BOLD}Enter key to use (e.g., 'b', 'c'): {Colors.ENDC}") + if len(key) != 1 or not key.isalpha(): + self.print_error("Invalid key. Must be a single letter.") + return + # Continue with the custom key + return self._add_shortcut_binding(tmux_conf, content, key) + else: + self.print_info("Installation cancelled") + return + # Get the full path to autoclaude-toggle script script_path = Path(__file__).parent.parent.parent / '.local' / 'bin' / 'autoclaude-toggle' if not script_path.exists(): @@ -476,11 +507,16 @@ class ClaudeCLI: self.print_error(f"autoclaude-toggle script not found") return + self._add_shortcut_binding(tmux_conf, content, 'a') + + def _add_shortcut_binding(self, tmux_conf: Path, content: str, key: str): + script_path = Path.home() / '.local' / 'bin' / 'autoclaude-toggle' + # Add the keybinding to tmux config - binding = f'\n# Toggle autoclaude automation for active pane and show status\nbind a run-shell "{script_path}"\n' + binding = f'\n# Toggle autoclaude automation for active pane and show status\nbind {key} run-shell "{script_path}"\n' tmux_conf.write_text(content + binding) - self.print_success(f"Added Ctrl+A+A shortcut to ~/.tmux.conf") + self.print_success(f"Added Ctrl+A+{key.upper()} shortcut to ~/.tmux.conf") self.print_info("Reload tmux config with: tmux source-file ~/.tmux.conf") self.print_info("Or restart your tmux session")