Hacker News new | ask | show | jobs
by dale-cooper 3940 days ago
I guess the downside of this is that ctrl+r would only search the current day's history? Personally I at least increased the history kept with HISTFILESIZE=500000 and HISTSIZE=5000
3 comments

Another issue is that it looks like would start a new history file only when a new shell is started. Some people log in fresh every day, but I've got terminal windows on my home machine that have been sitting around for many months...

I guess you'd have to set the history-size etc large enough to hopefully last for the maximum expected shell run-time.

EDIT: hmm, the man page says you can just unset HISTFILESIZE or set it to a non-numeric/negative value to avoid truncating the history file at all.

Yeah, I have this as well:

   export HISTSIZE=65535 # why not?
   export HISTFILESIZE=65535
   export HISTCONTROL=ignoredups
but now I'm wondering if I should unset `HISTFILESIZE` insteead.
It can also be nice to use HISTCONTROL=ignorespace

If you're planning on keeping a lot of history, ignorespace makes it easy to avoid inserting commands with sensitive info. A well-placed $(cat) can work too.

    $  PASSWORD=hunter2 # sensitive info doesn't go into history
    $ curl -O http://name:$PASSWORD@server/path # command with correct syntax does go into history
You can still use ctrl+r, but you need to provide the history file in one piece, using "history -r <file>" command. I do it in the following way, maybe it can serve you too:

  cat `find "${HOME}/.history" -type f | grep -v ".allhistory"` > ${HOME}/.history/.allhistory
  history -r ${HOME}/.history/.allhistory
There is another reply defining histgrep() function. Maybe ctrl+r could be assigned somehow.