-
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
A selected command from history is not executed on Ubuntu 24.04 #519
Comments
same on my ubuntu. |
Try this solution: #452 (comment) |
close the issue if it's been resolved btw |
This issue is not resolved, unless you want to force every Ubuntu user to play with sysctl. @dvorka You are ok with this? |
This helped me $ sudo sysctl -w dev.tty.legacy_tiocsti=1
$ sudo sh -c "echo 'dev.tty.legacy_tiocsti=1' > /etc/sysctl.d/9999-legacy-tiocsti.conf" |
I repost my reply from #478 as I think it might be relevant here as well, and this issue is open. 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. |
Hi,
after an upgrade on Ubuntu 24.04,
hstr
does not execute a selected command from history.Steps to reproduce
hstr
, i.e. CTRL+RThe text was updated successfully, but these errors were encountered: