Repository navigation
fix: handle multiline commands and history expansion in zsh integration - #21
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #15
Changes
Multiline commands: The widget now checks
$CONTEXTbefore intercepting. When zsh is collecting continuation input ($CONTEXT == "cont"— open quotes, backslash, braces,if/for/whilebodies), the Enter keypress is passed through unchanged. guard-sh intercepts only when$CONTEXTis"start", meaning the full command is assembled.History expansion: Added
zle .expand-historybefore reading$BUFFER. This resolves!!,!$,!cmdetc. to their expanded forms, so guard-sh evaluates the same command string that zsh will actually execute.