hstr icon indicating copy to clipboard operation
hstr copied to clipboard

Improvements to bash config code

Open norbusan opened this issue 1 year ago • 3 comments

Deciding upfront whether the kernel supports TIOCSTI or not might be difficult, so what about using this as bash init code?

####
# hstr configuration
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)

if [ -r /proc/sys/dev/tty/legacy_tiocsti ] ; then
  LEGACY_TIOCSTI=`cat /proc/sys/dev/tty/legacy_tiocsti`
else
  LEGACY_TIOCSTI=0
fi
if [ $LEGACY_TIOCSTI = 0 ] ; then
  function hstrnotiocsti {
    { HSTR_OUT="$( { </dev/tty hstr ${READLINE_LINE}; } 2>&1 1>&3 3>&- )"; } 3>&1;
    READLINE_LINE="$(hstr ${READLINE_LINE})"
    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 '""hstrnotiocsti"'; fi
  export HSTR_TIOCSTI=n
else
  # Optionally add the following lines to ~/.bashrc if TIOCSTI is supported by your OS:
  # if this is interactive shell, then bind hstr to Ctrl-r (for Vi mode check doc)
  if [[ $- =~ .*i.* ]]; then bind '"\C-r": "\C-a hstr -- \C-j"'; fi
fi

norbusan avatar Apr 17 '23 15:04 norbusan