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.08k stars 231 forks source link

hstr stops working on linux >=6.2.0 (depending on kernel config) #478

Closed leapfog closed 1 year ago

leapfog commented 1 year ago

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)

Mte90 commented 11 months ago

I didn't saw the new parameter for bash export HSTR_TIOCSTI=y I think that now it should work.

Dennysium commented 6 months ago

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.

jakedane commented 6 months ago

@Dennysium it's your configuration. Compare hstr --show-configuration output with what you have in your .bashrc file.

Dennysium commented 6 months ago

@Dennysium it's your configuration. Compare hstr --show-configuration output with what you have in your .bashrc file.

Thank you. I have appended the hstr --show-configuration output to my .bashrc, but still having the problem.

Dennysium commented 5 months ago

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.

jakedane commented 5 months ago

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.

Dennysium commented 5 months ago

@jakedane Thank you for the clarification. I run bash, this is my bashrc. The latter part is what I appended from hstrt --show-configuration:

 # ~/.bashrc: executed by bash(1) for non-login shells.
 # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
 # for examples

 # If not running interactively, don't do anything
 case $- in
     *i*) ;;
       *) return;;
 esac

 # don't put duplicate lines or lines starting with space in the history.
 # See bash(1) for more options
 #HISTCONTROL=ignoreboth

 # append to the history file, don't overwrite it
 shopt -s histappend

 # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
 #HISTSIZE=1000
 #HISTFILESIZE=2000

 # check the window size after each command and, if necessary,
 # update the values of LINES and COLUMNS.
 shopt -s checkwinsize

 # If set, the pattern "**" used in a pathname expansion context will
 # match all files and zero or more directories and subdirectories.
 #shopt -s globstar

 # make less more friendly for non-text input files, see lesspipe(1)
 [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

 # set variable identifying the chroot you work in (used in the prompt below)
 if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
     debian_chroot=$(cat /etc/debian_chroot)
 fi

 # set a fancy prompt (non-color, unless we know we "want" color)
 case "$TERM" in
     xterm-color|*-256color) color_prompt=yes;;
 esac

 # uncomment for a colored prompt, if the terminal has the capability; turned
 # off by default to not distract the user: the focus in a terminal window
 # should be on the output of commands, not on the prompt
 #force_color_prompt=yes

 if [ -n "$force_color_prompt" ]; then
     if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    # We have color support; assume it's compliant with Ecma-48
    # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    # a case would tend to support setf rather than setaf.)
    color_prompt=yes
     else
    color_prompt=
     fi
 fi

 if [ "$color_prompt" = yes ]; then
     PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
 else
     PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
 fi
 unset color_prompt force_color_prompt

 # If this is an xterm set the title to user@host:dir
 case "$TERM" in
 xterm*|rxvt*)
     PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
     ;;
 *)
     ;;
 esac

 # enable color support of ls and also add handy aliases
 if [ -x /usr/bin/dircolors ]; then
     test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
     alias ls='ls --color=auto'
     #alias dir='dir --color=auto'
     #alias vdir='vdir --color=auto'

     alias grep='grep --color=auto'
     alias fgrep='fgrep --color=auto'
     alias egrep='egrep --color=auto'
 fi

 # colored GCC warnings and errors
 #export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

 # some more ls aliases
 alias ll='ls -alF'
 alias la='ls -A'
 alias l='ls -CF'

 # Add an "alert" alias for long running commands.  Use like so:
 #   sleep 10; alert
 alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

 # Alias definitions.
 # You may want to put all your additions into a separate file like
 # ~/.bash_aliases, instead of adding them here directly.
 # See /usr/share/doc/bash-doc/examples in the bash-doc package.

 if [ -f ~/.bash_aliases ]; then
     . ~/.bash_aliases
 fi

 # enable programmable completion features (you don't need to enable
 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
 # sources /etc/bash.bashrc).
 if ! shopt -oq posix; then
   if [ -f /usr/share/bash-completion/bash_completion ]; then
     . /usr/share/bash-completion/bash_completion
   elif [ -f /etc/bash_completion ]; then
     . /etc/bash_completion
   fi
 fi
 #My custom aliases
 alias libreoffice="flatpak run org.libreoffice.LibreOffice/x86_64/stable"

 # 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}"
 function hstrnotiocsti {
     { READLINE_LINE="$( { </dev/tty hstr ${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
Dennysium commented 5 months ago

Just one more important note: Whe I use Ctrl + R ton invoke hstr, it works as expected. It does not work with hstr searchterm

sbrl commented 4 months ago

On Linux DEVICE_NAME 6.9.4-artix1-1 #1 SMP PREEMPT_DYNAMIC Wed, 12 Jun 2024 21:17:50 +0000 x86_64 GNU/Linux, hstr behaves as I would expect with the following in my .bashrc:


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, hstr puts the command you select into the command prompt for you to review, and then hitting enter again will execute the command.

....if you are like me and have a version-controlled bin and .bashrc, then this may be useful if you simultaneously use machines with kernel versions both above and below 6.2.0.

Edit: it's mysteriously stopped working today. Investigating.

pavel-kalmykov commented 4 months ago

For the record, it does not work with kernel 6.9.3-76060903-generic and zsh either. My .zshrc file has the same contents as in hstr --show-configuration.

epistax1s commented 3 months ago

July 18, 2024

Kernel version: 6.8.0-38-generic hstr version: 3.1.0 (2023-04-18T08:50:00) I have placed hstr --show-configuration in my ~/.zshrc file.

It still doesn't work. The command is just printed but not executed (it worked on earlier versions of Linux).

caretech-ca commented 3 months ago

Same issue here: command is echoed, not executed.

Mint 22, using bash Kernel version: 6.8.0-40-generic #40-Ubuntu SMP PREEMPT_DYNAMIC hstr version: "3.1.0" (2023-04-18T08:50:00)

hstr --show-configuration contents are appended to ~/.bashrc

It works from a root prompt ( sudo -i ) but not as regular user.

mortan commented 2 months ago

Same behavior for me (commands are echo'd but not executed):

uname -r
6.10.7-arch1-1

ZSH shell.

Is there any workaround for this problem?

Edit: ok this seems to work: https://github.com/dvorka/hstr/issues/452#issuecomment-1625158519