Live data from Hacker News

“I have [bash] history back to ~2003”

twitter.com

21–30 of 148 posts

Re: “I have [bash] history back to ~2003”

#21

bash history had never seemed to work for me between tmux windows. Commands are 'trapped' in their respective window and the last one to close 'wins' and writes its history over the others. So I end-up with never-closing task-based window sessions and occasionally copy-paste commands to a safe file for future reference. I really should investigate the root cause some day...

Your shell is likely configured to write to the file, instead of appending to it.

    shopt -s histappend
In your .bashrc should do. To have it write after every command take a look at http://unix.stackexchange.com/a/1292

Re: “I have [bash] history back to ~2003”

#22

bash history had never seemed to work for me between tmux windows. Commands are 'trapped' in their respective window and the last one to close 'wins' and writes its history over the others. So I end-up with never-closing task-based window sessions and occasionally copy-paste commands to a safe file for future reference. I really should investigate the root cause some day...

http://askubuntu.com/questions/67283/is-it-possible-to-make-... might do it?

(In zsh I believe it's:

    setopt inc_append_history
    setopt share_history
)

Re: “I have [bash] history back to ~2003”

#23
post #18
post #12

Earlier quoted context omitted.

echo "Password: "; read -s pass; stuff --pass "$pass" Where stuff takes password as an argument. Alternatively you can start your line with a space character and it isn't stored in your history.

The leading space behaviour is true only if HISTCONTROL="ignorespace" is set.

Did not know that, for me HISTCONTROL=ignoreboth is set in my .bashrc. I think Debian's adduser creates a default .bashrc file where this line is present, I'm not sure though.

Re: “I have [bash] history back to ~2003”

#24
post #12

Earlier quoted context omitted.

echo "Password: "; read -s pass; stuff --pass "$pass" Where stuff takes password as an argument. Alternatively you can start your line with a space character and it isn't stored in your history.

Cool, did not know that about the leading space.

Do be aware though that this only works if HISTCONTROL is set to 'ignorespace' or 'ignoreboth' (for bash anyway).

For zsh, you need to have HIST_IGNORE_SPACE set.

Re: “I have [bash] history back to ~2003”

#26
post #14
post #8

I recently set up my bash history to collect into an sqlite database. Besides the exact command it records the working directory, return value, starting time, ending time, a shell and a login session id. It doesn't handle background jobs well right now though.

I would love to use this! Had to grep through ancient backup diffs way too many times to resurrect that perfect command line.

I was interested myself too so had a quick search. There are a couple of implementations of the idea out there, https://code.google.com/p/advanced-shell-history/ looks the most promising of the ones I looked at. I might have to play with it later.

Re: “I have [bash] history back to ~2003”

#28
I use zsh per directory history [0] as well as this cron job I have set to run hourly:

    #!/bin/bash

    cd /Users/nmjohn/.directory_history \
      && git add . \
      && git commit -m "Automatic Backup: `date`" \
      && echo "Files Modified:" \
      && git log head -1 --name-only --pretty=format:"" | grep "[^\s]" | awk '{print    "\t\t"$0}' \
      && echo ""
It's not bullet-proof, but since I never manually touch the directory it's worked without hiccup for the last ~6 months. When trying to remember the syntax to a rarely used function (or even the name itself) or coming up with a gnarly awk/sed/grep command, it's been incredibly helpful to have fairly granular search capability to go back and find them weeks later.

Also ctrl+g in a terminal toggles between per directory history and global history which makes context switching easier when switching to a project not touched for a while.

[0]: https://github.com/jimhester/per-directory-history

Re: “I have [bash] history back to ~2003”

#30

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

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 se…

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.
Post reply on HN