Skip to content

Commit aa67f71

Browse files
authored
fix: apply command replacements to Bash TTS notifications (#13)
- 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 <cmd>" format and direct command replacements Fixes #11
1 parent d2f1cd6 commit aa67f71

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

src/ccnotify/notify.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ def migrate_replacements_format(old_data: Dict[str, Any]) -> Dict[str, Any]:
487487
"mkdir": "make directory",
488488
"npm": "N P M",
489489
"uvx": "U V X",
490+
"gh": "github CLI",
491+
"uv": "U V",
490492
}
491493

492494
# Add default patterns if empty
@@ -537,6 +539,8 @@ def load_replacements() -> Dict[str, Any]:
537539
"mkdir": "make directory",
538540
"npm": "N P M",
539541
"uvx": "U V X",
542+
"gh": "github CLI",
543+
"uv": "U V",
540544
},
541545
"patterns": [
542546
{"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
591595
# Then check direct command replacements
592596
cmd_parts = command.split()
593597
if cmd_parts:
594-
base_cmd = cmd_parts[0]
595-
if base_cmd in cmd_replacements:
596-
return cmd_replacements[base_cmd]
598+
# Check if first word is "running" and handle it specially
599+
if len(cmd_parts) > 1 and cmd_parts[0] == "running":
600+
base_cmd = cmd_parts[1]
601+
if base_cmd in cmd_replacements:
602+
# Replace the command after "running"
603+
parts = cmd_parts.copy()
604+
parts[1] = cmd_replacements[base_cmd]
605+
return " ".join(parts)
606+
else:
607+
# Check first word directly
608+
base_cmd = cmd_parts[0]
609+
if base_cmd in cmd_replacements:
610+
# Replace just the command part, preserve the rest
611+
parts = cmd_parts.copy()
612+
parts[0] = cmd_replacements[base_cmd]
613+
return " ".join(parts)
597614

598615
# Return the original command if no replacement found
599-
return f"running {cmd_parts[0]}" if cmd_parts else "running command"
616+
return command
600617

601618

602619
class NotificationHandler:
@@ -875,6 +892,9 @@ def handle_hook(self, hook_data: Dict[str, Any]):
875892
else:
876893
audio_desc = f"running {cmd_summary}"
877894

895+
# Apply command replacements for TTS
896+
audio_desc = apply_command_replacement(audio_desc, replacements)
897+
878898
# Build messages
879899
if target and len(target) < 50: # Sanity check on target length
880900
message = f"[{display_project_name}] Running {cmd_summary} on {target}"

0 commit comments

Comments
 (0)