Conversation
…n Zsh (Bash is impossible to fix) #507
There was a problem hiding this comment.
Pull request overview
Updates the non-TIOCSTI “insert into prompt” integration so Zsh users don’t need to press ENTER twice, aligning behavior with environments where command execution can be triggered immediately.
Changes:
- Update generated Zsh widget (and documented snippet) to detect an “execute” newline from
hstroutput and callzle accept-line. - Add/update example scripts under
test/sh/(including licensing headers and explanatory notes). - Refresh the manpage’s Zsh non-TIOCSTI configuration example accordingly.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| test/sh/tiotcsi-function-zsh.sh | Updates the Zsh no-TIOCSTI widget example to optionally auto-execute when hstr indicates execution. |
| test/sh/tiotcsi-function-bash.sh | Adds licensing header and documents Bash bind -x limitation requiring double-ENTER. |
| src/hstr.c | Updates --show-zsh-configuration output for no-TIOCSTI systems to support auto-execute via zle accept-line. |
| man/hstr.1 | Updates Zsh configuration documentation to match the new no-TIOCSTI auto-execute behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,4 +1,19 @@ | |||
| #!/usr/bin/env bash | |||
There was a problem hiding this comment.
The script is labeled as a Zsh example and uses ZLE/bindkey, but the shebang specifies Bash. Executing this file directly will fail under Bash; consider changing the shebang to zsh (or removing the shebang if it’s meant to be sourced from an existing zsh session).
| #!/usr/bin/env bash | |
| #!/usr/bin/env zsh |
| BUFFER="${HSTR_OUT}" | ||
| CURSOR=${#BUFFER} | ||
| zle redisplay | ||
| { HSTR_OUT="$( { </dev/tty hstr ${BUFFER}; echo -n x >&2; } 2>&1 1>&3 3>&-; )"; } 3>&1; |
There was a problem hiding this comment.
This invocation is missing the -- end-of-options marker (unlike the generated config and manpage). If the current BUFFER begins with a dash (e.g. -n), hstr will parse it as an option rather than a search term; add -- before ${BUFFER} here as well.
| #endif | ||
| ); | ||
| printf("\nexport HSTR_TIOCSTI=n"); | ||
| // note: due to Bash 'bind -x' limitations, users need to press ENTER twice on row insertion |
There was a problem hiding this comment.
The note about Bash needing ENTER twice is currently a C comment, so it will not appear in the generated --show-bash-configuration output. If this is intended for users, emit it as a # NOTE: line in the printed shell snippet (and/or document it in the manpage); otherwise remove the comment to avoid confusion.
| // note: due to Bash 'bind -x' limitations, users need to press ENTER twice on row insertion | |
| printf("\n# NOTE: Due to Bash 'bind -x' limitations, you may need to press ENTER twice after inserting a line from hstr"); |
| "\n BUFFER=\"${HSTR_OUT}\"" | ||
| "\n CURSOR=${#BUFFER}" | ||
| "\n zle redisplay" | ||
| "\n { HSTR_OUT=\"$( { </dev/tty hstr -- ${BUFFER}; echo -n x >&2; } 2>&1 1>&3 3>&-; )\"; } 3>&1;" |
There was a problem hiding this comment.
The generated Zsh snippet uses echo -n to emit a sentinel to stderr. echo option handling is not portable and can vary by shell/options; use a more reliable primitive (e.g. printf %s x >&2 or zsh’s print -n -- x >&2) for the sentinel.
| "\n { HSTR_OUT=\"$( { </dev/tty hstr -- ${BUFFER}; echo -n x >&2; } 2>&1 1>&3 3>&-; )\"; } 3>&1;" | |
| "\n { HSTR_OUT=\"$( { </dev/tty hstr -- ${BUFFER}; printf %s x >&2; } 2>&1 1>&3 3>&-; )\"; } 3>&1;" |
| BUFFER="${HSTR_OUT}" | ||
| CURSOR=${#BUFFER} | ||
| zle redisplay | ||
| { HSTR_OUT="$( { </dev/tty hstr -- ${BUFFER}; echo -n x >&2; } 2>&1 1>&3 3>&-; )"; } 3>&1; |
There was a problem hiding this comment.
This snippet uses echo -n for the stderr sentinel; echo option handling is not portable across shells/options. Prefer a reliable primitive like printf %s x >&2 (or zsh’s print -n -- x >&2) in the documentation example as well.
| { HSTR_OUT="$( { </dev/tty hstr -- ${BUFFER}; echo -n x >&2; } 2>&1 1>&3 3>&-; )"; } 3>&1; | |
| { HSTR_OUT="$( { </dev/tty hstr -- ${BUFFER}; printf %s x >&2; } 2>&1 1>&3 3>&-; )"; } 3>&1; |
🤖 Augment PR SummarySummary: This PR fixes the Zsh “no TIOCSTI” integration so selected commands don’t require pressing ENTER twice.
$(...) trimming trailing newlines so the widget can distinguish “selection+ENTER” from other exits.
🤖 Was this summary useful? React with 👍 or 👎 |
| "\n BUFFER=\"${HSTR_OUT}\"" | ||
| "\n CURSOR=${#BUFFER}" | ||
| "\n zle redisplay" | ||
| "\n { HSTR_OUT=\"$( { </dev/tty hstr -- ${BUFFER}; echo -n x >&2; } 2>&1 1>&3 3>&-; )\"; } 3>&1;" |
There was a problem hiding this comment.
Using echo -n as the sentinel here can be unreliable in zsh depending on options (e.g., BSD_ECHO/SH_ECHO) and could break the trailing-newline detection logic. Consider a more deterministic sentinel emitter so HSTR_OUT always ends with the marker exactly once.
Other Locations
man/hstr.1:235test/sh/tiotcsi-function-zsh.sh:105
🤖 Was this useful? React with 👍 or 👎
Tasks:
Related: