From bab4cba8aff9415f308403ab4d50b48daa5e78db Mon Sep 17 00:00:00 2001 From: Helmi Date: Fri, 12 Sep 2025 22:31:40 +0200 Subject: [PATCH] fix: apply command replacements to Bash TTS notifications - Add missing apply_command_replacement() call for Bash commands - Fix apply_command_replacement() to preserve full command structure - Add default replacements for gh (github CLI) and uv (U V) - Handle both "running " format and direct command replacements Fixes #11 --- src/ccnotify/notify.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/ccnotify/notify.py b/src/ccnotify/notify.py index f251293..2514954 100644 --- a/src/ccnotify/notify.py +++ b/src/ccnotify/notify.py @@ -487,6 +487,8 @@ def migrate_replacements_format(old_data: Dict[str, Any]) -> Dict[str, Any]: "mkdir": "make directory", "npm": "N P M", "uvx": "U V X", + "gh": "github CLI", + "uv": "U V", } # Add default patterns if empty @@ -537,6 +539,8 @@ def load_replacements() -> Dict[str, Any]: "mkdir": "make directory", "npm": "N P M", "uvx": "U V X", + "gh": "github CLI", + "uv": "U V", }, "patterns": [ {"pattern": "npm run (\\w+)", "replacement": "N P M run {1}"}, @@ -591,12 +595,25 @@ def apply_command_replacement(command: str, replacements: Dict[str, Any]) -> str # Then check direct command replacements cmd_parts = command.split() if cmd_parts: - base_cmd = cmd_parts[0] - if base_cmd in cmd_replacements: - return cmd_replacements[base_cmd] + # Check if first word is "running" and handle it specially + if len(cmd_parts) > 1 and cmd_parts[0] == "running": + base_cmd = cmd_parts[1] + if base_cmd in cmd_replacements: + # Replace the command after "running" + parts = cmd_parts.copy() + parts[1] = cmd_replacements[base_cmd] + return " ".join(parts) + else: + # Check first word directly + base_cmd = cmd_parts[0] + if base_cmd in cmd_replacements: + # Replace just the command part, preserve the rest + parts = cmd_parts.copy() + parts[0] = cmd_replacements[base_cmd] + return " ".join(parts) # Return the original command if no replacement found - return f"running {cmd_parts[0]}" if cmd_parts else "running command" + return command class NotificationHandler: @@ -875,6 +892,9 @@ def handle_hook(self, hook_data: Dict[str, Any]): else: audio_desc = f"running {cmd_summary}" + # Apply command replacements for TTS + audio_desc = apply_command_replacement(audio_desc, replacements) + # Build messages if target and len(target) < 50: # Sanity check on target length message = f"[{display_project_name}] Running {cmd_summary} on {target}"