-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hstr stops working on linux >=6.2.0 (depending on kernel config) #478
Comments
Edit: Never mind, probably only switchable with CONFIG_LEGACY_TIOCSTI=y.
It can't be set though.
Arch Linux 6.2.1 |
I came here as well cause hstr stopped working. Cheers |
❯ uname -r ❯ date Hstr is confirmed NOT working on the above kernel as of the time above. |
If you run |
I can confirm that it's the CONFIG_LEGACY_TIOCSTI option. I had the same problem after I updated my Gentoo to 6.2, and after reenabling that option in my Kernel, it started to work again with 6.2. |
Seems |
fzf has a bash function around it for the history function, that sets the readline input buffer with the history line that was selected in fzf. The same can be done with hstr! What I did:
Now if I open a new terminal, press Ctrl+R, hstr works again and the selected history line is placed on the readline input. I don't fully understand all of the above — and it can probably be cleaned up and made nicer — but at least I have a working hstr again. |
CopyQ is another candidate that still works. I'm not sure but i think they load the clipboard and send a keystroke via X11 to paste the text. |
Thanks @jakedane for the workaround. It works! |
I am on debian sid and stopped working too with
Compiled with the patch, it still not work. I just get the command in the terminal after the selection compared to before. |
That sounds like you did step 1 from #478 (comment) but didn't proceed with step 2 and 3 to modify your .bashrc file (and open a new terminal after). |
So I tried that bash changes and in this way works only Ctrl+r not
|
While I still hope for
I only confirmed that with |
I can confirm that with |
I can confirm too on Debian sid (siduction) with 6.2.6-1 the hstr package from debian repository works again. |
Re-enabling |
@Mte90 @chrischmo @karlovskiy @leapfog @jakedane @papavlos @mmeier86 thank you all for detailed descriptions of the problem, root cause identification and proposed solutions! I worked on a version of The PR just enables existing Anyway if the PR will work for you, I will fix it also for Do you think that it would make sense to release Thank you all your interest in |
@dvorka I built hstr with #481 and with LINUX_KERNEL_6 defined, I put the new config in my .bashrc and with that Ctrl+R works properly in Bash. Thank you! I'm on Arch Linux with kernel 6.2.6. No issue compiling. I don't know how to safely detect TIOCSTI is available. Probably too hacky and not portable but on Linux if |
Preliminary
Detect TIOCSTI from C:
|
The C code detects TIOCSTI correctly. I tested it both with The bash code does not detect it correctly. Edit: ah, removing the redirect to /dev/null I get |
@jakedane thank you for testing the code! It really helped. As |
…, updating year to 2023, removing WIP defines for TIOCSTI debugging #478
FYI working on the fix @ |
oh, i didn't see the bashrc changed |
I forgot I was still using the sysctl "fix", so I removed it and now hstr doesn't work for me. I'm using hstr 3.1.0 on arch linux, kernel 6.5.5, and my bashrc has the same lines as in jakedane's comment above. I can search history but pressing enter doesn't select the entry, it only echo'es it. |
You have to press Enter twice. 1st Enter puts the selected history item on the bash prompt, 2nd Enter runs it. If any expect hstr to work differently (that 1st Enter runs the command directly), I think that needs to be a separate issue. |
@eleius another suggestion is to select your command, use TAB to bring it to your prompt, and then press enter; removing the need to hit Enter twice. |
@jakedane @jasonnab I've already tried Tab+Enter and Enter+Enter, but for some reason when I press either Tab or Enter, the selected history item is just displayed as when you type the echo command (hstr doesn't bring it to the bash prompt.) |
@eleius, don't be upset. I have hstr behaving exactly the same way on Void Linux 6.3.13. |
any update for this issue? |
@Mte90 hstr 3.1.0 fixed the issue. Currently with bash 5.2.21 in gnome-terminal 3.50.1 (vte 0.74.1) on Arch Linux, kernel 6.6.3, with the output of If it doesn't work for you, what specifically are you using? |
I didn't saw the new parameter for bash |
I have the same problem on Ubuntu, since the upgrade to 24.04. That is kernel 6.8.0-31-generic and hstr 3.1.0 from the Ubuntu repos. |
@Dennysium it's your configuration. Compare |
Thank you. I have appended the hstr --show-configuration output to my .bashrc, but still having the problem. |
I have updated a second pc to Ubuntu 24.04 (This is a Kubuntu machine). I have appended the output of hstr --show-configuration to my .bashrc file and run source ~/.bashrc. I have the described problem. |
The NO_TIOCSTI issues were fixed with hstr 3.1.0. There's no problem with hstr on Ubuntu 24.04 for me. If it doesn't work for you, your configuration is wrong. Did you scrub the old configuration? It only works with bash or zsh. |
@jakedane
|
Just one more important note: |
On if [ "${NO_HH}" != "true" ] && [[ $- =~ .*i.* ]]; then
# hh / hstr configuration (https://github.com/dvorka/hstr/)
export HSTR_CONFIG=hicolor # get more colors
hstr_loc="";
if which hh >/dev/null 2>&1; then
hstr_loc="hh";
elif which hstr >/dev/null 2>&1; then
hstr_loc="hstr";
fi
hstr_mode="$($hstr_loc --is-tiocsti)";
if [[ "${hstr_mode}" == "n" ]]; then
# erk, no tiocsti available.
function hstrnotiocsti {
{ READLINE_LINE="$( { </dev/tty ${hstr_loc} ${READLINE_LINE}; } 2>&1 1>&3 3>&- )"; } 3>&1;
READLINE_POINT=${#READLINE_LINE}
}
# if this is interactive shell, then bind hstr to Ctrl-r (for Vi mode check doc)
if [[ $- =~ .*i.* ]]; then bind -x '"\C-r": "hstrnotiocsti"'; fi
export HSTR_TIOCSTI=n
else
# tiocsti is enabled, bind as normal
bind '"\C-r": "\C-a '"${hstr_loc}"' \C-j"';
fi
unset hstr_mode
unset hstr_loc
fi ....in other words, ....if you are like me and have a version-controlled Edit: it's mysteriously stopped working today. Investigating. |
For the record, it does not work with kernel |
July 18, 2024Kernel version: It still doesn't work. The command is just printed but not executed (it worked on earlier versions of |
Same issue here: command is echoed, not executed. Mint 22, using bash
It works from a root prompt ( |
Same behavior for me (commands are echo'd but not executed):
ZSH shell. Is there any workaround for this problem? Edit: ok this seems to work: #452 (comment) |
I use my own selection program instead of Even though I use my own selection program, I think I got the Bash integration from if [[ $- =~ .*i.* ]]; then bind '"\C-r": "\C-a rlselect-history \C-j"'; fi Here is how set -e
result=$(tac ~/.bash_history | rlselect --tab --action -- "$@")
python - "$result" << EOF
import fcntl
import sys
import termios
action, selection = sys.argv[1].split("\n", 1)
if action != "tab":
selection += "\n"
for ch in selection:
fcntl.ioctl(sys.stdout.fileno(), termios.TIOCSTI, ch)
EOF It calls The new snippet that I came up with for rlselect-history() {
local action
local selection
{
read action
read selection
} < <(tac ~/.bash_history | rlselect --tab --action -- "${READLINE_LINE}")
if [ "$action" = "tab" ]; then
READLINE_LINE="${selection}"
READLINE_POINT=${#READLINE_LINE}
bind '"\C-x2":' # Bind Ctrl+x+2 to do nothing
elif [ "$action" = "enter" ]; then
READLINE_LINE="${selection}"
READLINE_POINT=${#READLINE_LINE}
bind '"\C-x2": accept-line' # Bind Ctrl+x+2 to accept line
else
bind '"\C-x2":' # Bind Ctrl+x+2 to do nothing
fi
}
if [[ $- =~ .*i.* ]]; then
# Bind history commands to Ctrl+x+1 followed by Ctrl+x+2:
bind '"\C-r": "\C-x1\C-x2"'
# Bind Ctrl+x+1 to execute rlselect-history which does two things:
# 1. Sets READLINE_*
# 2. Binds Ctrl+x+2 to either accept line or do nothing.
bind -x '"\C-x1": rlselect-history'
fi The trick to finding this solution for me was understanding Bash key bindings. This answer on StackOverflow writes the following:
The old key binding can then be explained as follows: if [[ $- =~ .*i.* ]]; then bind '"\C-r": "\C-a rlselect-history \C-j"'; fi
(This also makes the text Let's break down the new key bindings the same way: if [[ $- =~ .*i.* ]]; then
# Bind history commands to Ctrl+x+1 followed by Ctrl+x+2:
bind '"\C-r": "\C-x1\C-x2"'
# Bind Ctrl+x+1 to execute rlselect-history which does two things:
# 1. Sets READLINE_*
# 2. Binds Ctrl+x+2 to either accept line or do nothing.
bind -x '"\C-x1": rlselect-history'
fi
So the new mechanism relies on using two extra key bindings: Ctrl+X+1 and Ctrl+X+2. I chose them because I don't use them otherwise. But they can be any two key bindings. Perhaps that makes it difficult to provide as a default config for I think a similar solution is presented in this thread and in other places. I didn't fully understand those examples when I first read them. I think now I do becasue of my new understanding of how Bash works. Hopefully my explanation can add value to someone. |
I'm reopening this issue because it's not completely resolved... |
Just wanted to leave a note, that hstr stops working with linux kernel 6.2.0, when CONFIG_LEGACY_TIOCSTI isn't set. So maybe you want to add that information to a trouble shooting guide or FAQ or something.
(re: "stops working": the history can still be browsed, but cannot be inserted anymore)
The text was updated successfully, but these errors were encountered: