4 ms·
Wow, cool! How does this handle the case of multiple shells writing to the history at the same time? I have yet to find a safe way to preserve all that.
by chongli 10y ago
Wow, cool! How does this handle the case of multiple shells writing to the history at the same time? I have yet to find a safe way to preserve all that.
- zootboy 10y agoAdd this to your .bashrc: # History stuff. shopt -s histappend export HISTFILESIZE=50000 export HISTSIZE=50000 export HISTCONTROL=ignoreboth export PROMPT_COMMAND='history -a' Individual shells keep their session history in order, while all commands regardless of which shell triggered them get appended to the history file.
- web007 10y ago# infinite history HOSTNAME="$(hostname)" HOSTNAME_SHORT="${HOSTNAME%%.*}" mkdir -p "${HOME}/.history/$(date -u +%Y/%m/)" > /dev/null 2>&1 SESSIONPREFIX=$(date -u +%Y/%m/%d.%H.%M.%S) export HISTFILE="${HOME}/.history/${SESSIONPREFIX}_${HOSTNAME_SHORT}_$$" Only thing you're missing is `HISTFILE`, and an alias like alias histgrep='find ~/.history/ -type f -print0 2>/dev/null | xargs -0 grep --color=auto -InH' https://news.ycombinator.com/item?id=10162189 https://news.ycombinator.com/item?id=10162189 for context
- jesrui 10y agoSame idea with some usage and backup tips: http://jesrui.sdf-eu.org/remember-all-your-bash-history-forever.html http://jesrui.sdf-eu.org/remember-all-your-bash-history-fore...
- 0x09 10y agoLooking at the script, it doesn't write any history itself, it just loads whatever is in the existing .bash_history into its db when `hist import` is invoked (when a new shell is started if you add it to your .profile like the readme recommends.) So this does not do anything to manage different sessions clobbering each others' histories. The solution posted by zootboy will work together with this script however.
- jcsalterego 10y agoFWIW, my understanding of sqlite is that it allows atomic operations against the same DB, even if there are different clients... so I would guess at worst the clobbering is minimal. I could be wrong, though.