Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I lifted most of this from the guy mentioned in the hn post in the comments below. I don't know what shell/platform he used, but it didn't work from twitter so I tweaked it to work on the linux boxes I typically see.

It creates a different history file from each shell session. Most of my shell history goes back about 3 years now. The downside is you can't up arrow or crtl R except for your current history, but you can use the histgrep function to search everything.

I keep meaning to make another processed file which would uniq the history without the datestamp and maybe hook into fzf, but this has been good enough for now.

  # tricks from https://news.ycombinator.com/item?id=10162189

  if [ ! -d ~/.history/$(date -u +%Y/%m/) ]; then
        mkdir -p ~/.history/$(date -u +%Y/%m/)
  fi
  #cat .history/2016/09/* |sort -n| uniq

  export HISTFILE="${HOME}/.history/$(date -u +%Y/%m/%d.%H.  %M.%S)_${HOSTNAME}_$$"
  export HISTSIZE=
  export HISTCONTROL=ignoreboth
  export HISTCONTROL=erasedups
  export HISTTIMEFROMAT="%d/%m/%Y-%H:%M:%S"
  #export PROMPT_COMMAND='history -a'
  export HISTIGNORE='&:bg:fg:clear:ls:pwd:history:exit:make*:* --help:'
  export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
  histgrep () 
  {
  grep -r "$@" ~/.history
  history | grep "$@"
  }


There may be a typo in in this line

export HISTTIMEFROMAT="%d/%m/%Y-%H:%M:%S"

should HISTTIMEFROMAT be HISTTIMEFORMAT ?


HISTIGNORE is really cool




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: