hstr
hstr copied to clipboard
TIOCSTI mess
There are several issues concerning this problem: https://github.com/dvorka/hstr/issues/478, https://github.com/dvorka/hstr/issues/485, https://github.com/dvorka/hstr/issues/486
The suggested bash snippets differ in all places:
- https://github.com/dvorka/hstr/blob/master/test/sh/tiotcsi-function-bash.sh#L190-L194
- hstr --show-bash-config
- man hstr (could be a debian/sid problem)
- https://github.com/dvorka/hstr/issues/485#issuecomment-1516577488
For security reasons it seem best to not use the legacy TIOCSTI. Please handle this internally or provide robust source-able shell configurations. hstr --show-[XXX]-config
is almost good except that it is not reliably working.
I have tried several suggestions and none seems to work reliable. The one I am using currently works only with extra confirmation and has sometimes garbage in the output.
» cat ~/.bashrc.d/all/history
#!/usr/bin/env bash
## History Commands
HISTFILESIZE=50000
shopt -s cmdhist
export HISTFILE=~/.cache/.bash_history # replace with /dev/null
export HISTIGNORE="&:ls:exit:su*"
# append to the history file, don't overwrite it
shopt -s histappend
HISTCONTROL=ignoreboth # leading space hides commands from history & dupes are irgnored
## hstr configuration
alias hh=hstr # hh to be alias for hstr
export HSTR_CONFIG=hicolor # get more colors
export HISTSIZE=${HISTFILESIZE} # increase history size (default is 500)
# done in prompt file
# ensure synchronization between Bash memory and history file
#export PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}"
has_tiocsti="$(hstr --is-tiocsti)"
if [[ "$has_tiocsti" == "y" ]]; then
# REQUIRES
# sysctl -w dev.tty.legacy_tiocsti=1
# sudo sh -c "echo 'dev.tty.legacy_tiocsti=1' > /etc/sysctl.d/9999-legacy-tiocsti.conf"
if [[ $- =~ .*i.* ]]; then
bind '"\C-r": "\C-a hstr -- \C-j"'
bind '"\C-xk": "\C-a hstr -k \C-j"'
bind -m vi-insert '"\C-r": "\C-u hstr -- \C-j"'
bind -m vi '"\C-r": "ddi hstr -- \C-j"'
fi
else
##TODO
#hstr stops working on linux >=6.2.0 (depending on kernel config)
#https://github.com/dvorka/hstr/issues/478
##TODO END
function hstrnotiocsti {
{ READLINE_LINE="$( { </dev/tty hstr -- ${READLINE_LINE}; } 2>&1 1>&3 3>&- )"; } 3>&1;
READLINE_POINT=${#READLINE_LINE}
}
if [[ $- =~ .*i.* ]]; then
bind -x '"\C-r": "hstrnotiocsti"'
fi
export HSTR_TIOCSTI=n
fi