hstr icon indicating copy to clipboard operation
hstr copied to clipboard

Running a previous command with hstr echoes instead of running the command

Open davidhaley opened this issue 2 years ago • 11 comments

I'm not sure what could be causing this.

For example:

echo testing

testing

Then, I press ctrl+r, search for testing, and press enter on the command that we just ran and it echoes:

hstr --

Or, if I use the alias hh, find the previous command and run it:

hh

My config in .bashrc is:

# HSTR configuration - add this to ~/.bashrc
alias hh=hstr                    # hh to be alias for hstr
export HSTR_CONFIG=hicolor       # get more colors
shopt -s histappend              # append new history items to .bash_history
export HISTCONTROL=ignorespace   # leading space hides commands from history
export HISTFILESIZE=10000        # increase history file size (default is 500)
export HISTSIZE=${HISTFILESIZE}  # increase history size (default is 500)
# ensure synchronization between bash memory and history file
export PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}"
# if this is interactive shell, then bind hstr to Ctrl-r (for Vi mode check doc)
if [[ $- =~ .*i.* ]]; then bind '"\C-r": "\C-a hstr -- \C-j"'; fi
# if this is interactive shell, then bind 'kill last command' to Ctrl-x k
if [[ $- =~ .*i.* ]]; then bind '"\C-xk": "\C-a hstr -k \C-j"'; fi

hstr version "2.5.0" (2021-12-13T22:00:00)

davidhaley avatar May 29 '22 15:05 davidhaley

Under Haiku we get that same behavior. Upon hitting ENTER after selecting an entry from the history, it gets printed on the console.

Currently using bash version 5.1.16, and hstr 2.5.0 (but it happened too with the original Haiku port of hstr, that was was at version 2.0).

@davidhaley: can you share more info regarding your OS, terminal app, and bash version? Maybe by comparing info, we can start to narrow the search of where the problem might lie.

OscarL avatar Oct 09 '22 11:10 OscarL

For the record. The issue on the Haiku port was that it needs to use the same bash function as the CYGWIN port (as Haiku also lacks TIOCSTI):

https://github.com/dvorka/hstr/blob/be59f8cf5a48af43a66963c8220b888563aeea0c/src/hstr.c#L193

And that wasn't reflected on the install/config instructions.

Defining that hstr_cygwin() (I guess it could be called hstr_no_tiocsti() now) bash function and binding it to CTRL+R now works like a charm!

Time to fix/update the Haiku package :-)

OscarL avatar Oct 09 '22 13:10 OscarL

I'm on Archlinux and I am also having this problem. Maybe related also to , https://github.com/dvorka/hstr/issues/346 ?

I do remember it was working fine some weeks ? month? ago.

But now, whatever I choose after running "hstr", it always "echoes it", and puts it before the prompt .

It doesnt give me any chance to either,

  • spit it out to the prompt and let me edit it, on the prompt, before entering ENTER and executing
  • spit it out and run it immediately

$ hstr --version

hstr version "3.1.0" (2023-04-18T08:50:00)

Running it says,

RET/TAB select,

the man page itself is not very consistent with this information,

       TAB, RIGHT arrow
              Choose currently selected item for completion and let user to
              edit it on the command prompt.

       ENTER  Choose currently selected item for completion and execute it.

I'v also tried it in different terminals and with zero configurations or customizations on bashrc.

sudo useradd - test_user su -l test_user

Same problem. Wether I choose "RETURN", "TAB" or "RIGHT", i never get that line of history in the prompt. It always gets printed before the prompt.

Other functionalities like, favourites, deleting etc seems to be working

m040601 avatar Apr 20 '23 11:04 m040601

Same problem as above on Manjaro

hstr version "3.1.0" (2023-04-18T08:50:00)

vparitskiy avatar May 18 '23 10:05 vparitskiy

Must be some kernel thing as It was working for me fine on Debian Sid until I did a kernel upgrade to 6.3.0-1-amd64 and now it echo's but if you type echo !! you notice it doesn't show an echo command.

hstr version "3.1.0" (2023-04-18T08:50:00) as the others

EDIT: Just noticed this has been mentioned in a bigger issue https://github.com/dvorka/hstr/issues/478 and solution seems to be to run command sysctl -w dev.tty.legacy_tiocsti=1

smahm006 avatar Jul 02 '23 07:07 smahm006

@s-mahm solution of running sysctl -w dev.tty.legacy_tiocsti=1 worked for me. Thank you!

silvan-talos avatar Jul 07 '23 09:07 silvan-talos

To ensure that this persists across system restarts on distros using recent systemd versions, create new conf file:

sudo sh -c "echo 'dev.tty.legacy_tiocsti=1' > /etc/sysctl.d/9999-legacy-tiocsti.conf"

vparitskiy avatar Jul 07 '23 09:07 vparitskiy

sysctl -w dev.tty.legacy_tiocsti=1

There is a reason they disabled that. It's a security issue.

https://cateee.net/lkddb/web-lkddb/LEGACY_TIOCSTI.html

So, anybody who wants to disable it, just be aware that there are things in the wild which use that for privilege escalation.

I guess I can live with it just printing instead of allowing me to edit, but that only works on the newest versions of hstr. If you are using an older version that is packaged in Ubuntu or Debian's current stable repositories, you don't even get that. You just get a return to the shell with nothing printed at all.

Danathar avatar Nov 17 '23 19:11 Danathar

I also get tis on arch, and the @s-mahm solution corrects it.

plum avatar Feb 29 '24 23:02 plum