Skip to content

fix: handle multiline commands and history expansion in zsh integration - #21

Merged
berdanakyurek merged 2 commits into
developfrom
claude-1/issue-15-zsh-edge-cases
Mar 15, 2026
Merged

berdanakyurek merged 2 commits into
developfrom
claude-1/issue-15-zsh-edge-cases

Conversation

@berdanakyurek

Copy link
Copy Markdown
Owner

Closes #15

Changes

Multiline commands: The widget now checks $CONTEXT before intercepting. When zsh is collecting continuation input ($CONTEXT == "cont" — open quotes, backslash, braces, if/for/while bodies), the Enter keypress is passed through unchanged. guard-sh intercepts only when $CONTEXT is "start", meaning the full command is assembled.

History expansion: Added zle .expand-history before reading $BUFFER. This resolves !!, !$, !cmd etc. to their expanded forms, so guard-sh evaluates the same command string that zsh will actually execute.

claude-developer-1 Bot and others added 2 commits March 15, 2026 23:12
Two edge cases were untested and broken:

1. Multiline commands — the widget was firing on the first line before
   the full command was assembled. Now checks $CONTEXT: if it is 'cont'
   (zsh waiting for more input due to open quotes, backslash, braces,
   if/for/while bodies etc.), the Enter is passed through unchanged.
   guard-sh intercepts only when $CONTEXT is 'start' (complete input).

2. History expansion — !! / !$ / !cmd tokens were passed raw to
   guard-sh, so it evaluated a different command than what would
   actually run. Now calls `zle .expand-history` before reading
   $BUFFER, so the expanded form is checked.

Closes #15

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@berdanakyurek
berdanakyurek merged commit 464b542 into develop Mar 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant