You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

  1. # save history for multiple terminals
  2. # create a folder to store the history
  3. if [ ! -d "${HOME}/.bash_history_log" ]; then
  4. mkdir "${HOME}/.bash_history_log"
  5. fi
  6. # Add the tty to the history file
  7. # Each terminal's history will be stored in
  8. # its own file
  9. if [ ! -z "${TMUX_PANE}" ]; then
  10. HISTSUFFIX="${TMUX_PANE}"
  11. else
  12. HISTSUFFIX=`tty | sed 's/\///g;s/^dev//g'`
  13. fi
  14. HISTFILE="$HOME/.bash_history_log/bash_history_$HISTSUFFIX"
  15. # Time stamp for the history
  16. HISTTIMEFORMAT="%y-%m-%d %H:%M:%S "
  17. # don't put duplicate lines or lines starting with space in the history.
  18. HISTCONTROL=ignoredups:ignorespace
  19. # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
  20. HISTSIZE=1000
  21. HISTFILESIZE=5000
  22. # append to the history file, don't overwrite it
  23. shopt -s histappend
  24. # Add to the history everytime the prompt is shown
  25. PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007";history -a'
  26. # Search history
  27. function searchhistory() {
  28. grep -ri "${1}" ~/.bash_history_log/*
  29. }
  30. alias shistory=searchhistory
  31. # Thanks for that: https://dev.to/mrrcollins/saving-bash-history-across-terminals-b80