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.

35 lines
1.0 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. HISTSUFFIX=`tty | sed 's/\///g;s/^dev//g'`
  10. HISTFILE="$HOME/.bash_history_log/bash_history_$HISTSUFFIX"
  11. # Time stamp for the history
  12. HISTTIMEFORMAT="%y-%m-%d %H:%M:%S "
  13. # don't put duplicate lines or lines starting with space in the history.
  14. HISTCONTROL=ignoredups:ignorespace
  15. # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
  16. HISTSIZE=1000
  17. HISTFILESIZE=5000
  18. # append to the history file, don't overwrite it
  19. shopt -s histappend
  20. # Add to the history everytime the prompt is shown
  21. PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007";history -a'
  22. # Search history
  23. function searchhistory() {
  24. grep -ri "${1}" ~/.bash_history_log/*
  25. }
  26. alias shistory=searchhistory
  27. # Thanks for that: https://dev.to/mrrcollins/saving-bash-history-across-terminals-b80