Skip to content
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

TIOCSTI mess #501

Open
ObiWahn opened this issue Oct 14, 2023 · 1 comment
Open

TIOCSTI mess #501

ObiWahn opened this issue Oct 14, 2023 · 1 comment

Comments

@ObiWahn
Copy link

ObiWahn commented Oct 14, 2023

There are several issues concerning this problem: #478, #485, #486

The suggested bash snippets differ in all places:

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
@jakedane
Copy link

jakedane commented Dec 5, 2023

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 hstr --show-configuration in the .bashrc file, that works without problems. The kernel is not compiled with CONFIG_LEGACY_TIOCSTI set and dev.tty.legacy_tiocsti is also not set.

Which OS and terminal are you using? What versions?

@dvorka dvorka self-assigned this Feb 24, 2024
@dvorka dvorka added this to the 3.1 TIOCSTI strikes back! milestone Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants