dvorka / hstr

bash and zsh shell history suggest box - easily view, navigate, search and manage your command history.
http://me.mindforger.com
Apache License 2.0
4.03k stars 231 forks source link

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

Open davidhaley opened 2 years ago

davidhaley commented 2 years ago

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)

OscarL commented 1 year ago

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 commented 1 year ago

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

m040601 commented 1 year ago

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,

$ 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

vparitskiy commented 1 year ago

Same problem as above on Manjaro

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

smahm006 commented 1 year ago

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

silvan-talos commented 1 year ago

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

vparitskiy commented 1 year ago

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"

Danathar commented 10 months ago

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.

plum commented 6 months ago

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

smahm006 commented 3 months ago

@davidhaley Can you close this issue if it was resolved?

davidhaley commented 3 months ago

@davidhaley Can you close this issue if it was resolved?

Sorry, I haven't had this installed now for quite some time.

ElectronicBattle commented 3 weeks ago

It was working on linux mint 21.3 (ubuntu 22.04) but upgrading to LM22 (24.04) causes this problem.

Summarising earlier posts from @leapfog and @vparitskiy (and making them even more clear for people like me, i.e. not very expert in the linux environment!), this is what I did:

sudo sysctl -w dev.tty.legacy_tiocsti=1 and then sudo sh -c "echo 'dev.tty.legacy_tiocsti=1' > /etc/sysctl.d/9999-legacy-tiocsti.conf" worked for me too. Maybe the cause was the kernel change associated with my OS upgrade? Current kernel is 6.8.0-40-generic

[edited to reference the earlier posts so that the brain power is correctly ascribed]

SilkovAlexander commented 2 weeks ago

It was working on linux mint 21.3 (ubuntu 22.04) but upgrading to LM22 (24.04) causes this problem.

sudo sysctl -w dev.tty.legacy_tiocsti=1 and then sudo sh -c "echo 'dev.tty.legacy_tiocsti=1' > /etc/sysctl.d/9999-legacy-tiocsti.conf" worked for me too. Maybe the cause was the kernel change associated with my OS upgrade? Current kernel is 6.8.0-40-generic

Thank you a lot, that worked for me on Ubuntu 22.04

Handrail9 commented 1 week ago

@davidhaley Can you close this issue if it was resolved?

I don't think the issue was resolved if the solution is turning off a protection against privilege escalation. @dvorka is there any status update on this issue? I really love this program but I don't feel comfortable with the current solution being proposed here and it's been open for over two years. If it makes any difference I'm not on a Debian or Arched based distro, I'm on Fedora so this seems to affect all three of the big linux base distros.