Skip to content

fix(insert): 🐛 fixing need to hit ENTER twice on system w/o TIOCSTI in Zsh (Bash is impossible to fix) #507#555

Open
dvorka wants to merge 1 commit intodev-3.2.0from
bug-507/double-enter-wo-tiocsti
Open

fix(insert): 🐛 fixing need to hit ENTER twice on system w/o TIOCSTI in Zsh (Bash is impossible to fix) #507#555
dvorka wants to merge 1 commit intodev-3.2.0from
bug-507/double-enter-wo-tiocsti

Conversation

@dvorka
Copy link
Owner

@dvorka dvorka commented Jan 26, 2026

Tasks:

  • ENTER must NOT be used when user just wants to edit the selected line (Right Arrow), only when they select row w/ ENTER

Related:

@dvorka dvorka requested a review from Copilot January 26, 2026 20:34
@dvorka dvorka self-assigned this Jan 26, 2026
@dvorka dvorka changed the title fix(insert): 🐛 fixing need to hit ENTER twice on system w/o TIOCS… fix(insert): 🐛 fixing need to hit ENTER twice on system w/o TIOCSTI in Zsh (Bash is impossible to fix) #507 Jan 26, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hstr output and call zle 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
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
#!/usr/bin/env bash
#!/usr/bin/env zsh

Copilot uses AI. Check for mistakes.
BUFFER="${HSTR_OUT}"
CURSOR=${#BUFFER}
zle redisplay
{ HSTR_OUT="$( { </dev/tty hstr ${BUFFER}; echo -n x >&2; } 2>&1 1>&3 3>&-; )"; } 3>&1;
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
#endif
);
printf("\nexport HSTR_TIOCSTI=n");
// note: due to Bash 'bind -x' limitations, users need to press ENTER twice on row insertion
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// 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");

Copilot uses AI. Check for mistakes.
"\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;"
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"\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;"

Copilot uses AI. Check for mistakes.
BUFFER="${HSTR_OUT}"
CURSOR=${#BUFFER}
zle redisplay
{ HSTR_OUT="$( { </dev/tty hstr -- ${BUFFER}; echo -n x >&2; } 2>&1 1>&3 3>&-; )"; } 3>&1;
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
{ 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;

Copilot uses AI. Check for mistakes.
@augmentcode
Copy link

augmentcode bot commented Jan 26, 2026

🤖 Augment PR Summary

Summary: This PR fixes the Zsh “no TIOCSTI” integration so selected commands don’t require pressing ENTER twice.
Changes:

  • Update the Zsh widget snippets (generated install code, man page example, and test script) to preserve/detect a trailing newline via a sentinel and call zle accept-line when appropriate.
  • Add a note documenting the Bash bind -x limitation that prevents auto-executing the inserted command.
  • Add Apache 2.0 headers and minor cleanups to the experimental shell scripts.
Technical Notes: The sentinel avoids $(...) trimming trailing newlines so the widget can distinguish “selection+ENTER” from other exits.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

"\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;"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:235
  • test/sh/tiotcsi-function-zsh.sh:105

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running as root doesn't make you double-enter the choice without TIOCSTI

2 participants