Skip to content

Commit 80990a1

Browse files
committed
refactor(iterm2): simplify init save call and clean up string quoting
- collapse conditional save_window_id call into single unconditional call - fix applescript string quoting to use consistent single-quoted style - collapse multi-line escaped_session_id assignment to one line - update test assertion to match new save_window_id signature
1 parent f8dcbee commit 80990a1

2 files changed

Lines changed: 5 additions & 16 deletions

File tree

cc_notifier.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,7 @@ def cmd_init() -> None:
114114
window_id, app_path = "UNAVAILABLE", "UNAVAILABLE"
115115
debug_log(f"Window capture failed, continuing without: {e}")
116116
tmux_session_id = get_tmux_session_id() or ""
117-
if iterm2_session_id:
118-
save_window_id(
119-
hook_data.session_id,
120-
window_id,
121-
app_path,
122-
tmux_session_id,
123-
iterm2_session_id,
124-
)
125-
else:
126-
save_window_id(hook_data.session_id, window_id, app_path, tmux_session_id)
117+
save_window_id(hook_data.session_id, window_id, app_path, tmux_session_id, iterm2_session_id)
127118

128119

129120
@handle_command_errors("notify")
@@ -551,11 +542,11 @@ def get_iterm2_focused_session_id() -> str:
551542
"""Get iTerm2 focused session ID, or empty string when unavailable."""
552543
script_lines = [
553544
'tell application "iTerm2"',
554-
"if not running then return \"\"",
545+
'if not running then return ""',
555546
"try",
556547
"return id of current session of current window as text",
557548
"on error",
558-
"return \"\"",
549+
'return ""',
559550
"end try",
560551
"end tell",
561552
]
@@ -571,9 +562,7 @@ def get_iterm2_focused_session_id() -> str:
571562

572563
def _build_iterm2_restore_script(iterm2_session_id: str) -> str:
573564
"""Build AppleScript that focuses iTerm2 on a specific session ID."""
574-
escaped_session_id = (
575-
iterm2_session_id.replace("\\", "\\\\").replace('"', '\\"')
576-
)
565+
escaped_session_id = iterm2_session_id.replace("\\", "\\\\").replace('"', '\\"')
577566
return f"""tell application "iTerm2"
578567
if not running then return
579568
repeat with w in windows

tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def test_debug_flag_parsing(self, tmp_path):
110110
mock_stdin.assert_called_once()
111111
mock_window.assert_called_once()
112112
mock_save.assert_called_once_with(
113-
"test", "12345", "/System/Applications/Utilities/Terminal.app", ""
113+
"test", "12345", "/System/Applications/Utilities/Terminal.app", "", ""
114114
)
115115

116116
finally:

0 commit comments

Comments
 (0)