feat(zsh): history expansion inlay preview#52
Open
radiosilence wants to merge 6 commits intomainfrom
Open
Conversation
ZLE widget that shows dimmed preview of what history expansion chars (!!, !$, !^, ^foo^bar) would expand to before Enter. Uses add-zle-hook-widget to chain into zle-line-pre-redraw — appends to POSTDISPLAY instead of clobbering it, so zsh-autosuggestions still works. Disable via zstyle ':hist-preview' enabled no. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Use absolute offsets (autosuggestions-compatible) instead of P-prefix - Remove highlight entries by value not index (avoids shift bugs) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Show expansion on the same line (→ expanded) instead of below. Replaces autosuggestion when expansion is active — more useful context. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Wider gap before arrow for readability - Use [ ] instead of [[ ]] for buffer comparison — avoids * in !!:* being treated as glob pattern in the != check Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Replace zle expand-history with manual history parsing — avoids triggering widget events that let autosuggestions clobber POSTDISPLAY - Fix unicode arrow: use $'\u2192' (zsh escape) not bare \u2192 - Support: !!, !$, !^, !!:*, !!:$, !!:^, !!:0-9, ^old^new - Sets POSTDISPLAY directly without intermediate widget calls Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The pre-redraw hook fires at the wrong stage — autosuggestions overwrites POSTDISPLAY via widget wrapping, which runs after our hook. Fix: wrap editing widgets ourselves, chaining after autosuggestions' wrappers so we get final say on POSTDISPLAY. Each keystroke now: widget → autosuggestions → our preview. Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Summary
!!,!$,!^,^foo^bar, etc.) would expand to before pressing Enteradd-zle-hook-widget— doesn't clobberzsh-autosuggestionsor otherzle-line-pre-redrawhandlers→ expanded_commandzle expand-historyinternally (zsh's own expansion logic, handles all edge cases)zstyle ':hist-preview' enabled noHow it works
On each line redraw, if
!or leading^detected in the buffer:zle expand-historyto expand in-placeRecursion guard prevents expand-history → redraw → expand-history loops.
Test plan
!!— should show dimmed preview of last command below the linesudo !!— preview showssudo <last_command>!$— preview shows last argument of previous command^foo^bar— preview shows last command with substitution!) — no preview, autosuggestions works normallyzstyle ':hist-preview' enabled no— disables the widget🤖 Generated with Claude Code