What I do it HISTFILE=$HOME/.history/`hostname`.history so then I have a nice record of what I've done on all the machines I log into. This is particularly nice when you have a central home directory.
Keeping bash history in sync between multiple terminals
21–30 of 35 posts
Re: Keeping bash history in sync between multiple terminals
#22Earlier quoted context omitted.
How? (I use zsh. I also downvoted you.)
He's joking that Zsh isn't Bash and therefor doesn't keep Bash's history in sync.
Re: Keeping bash history in sync between multiple terminals
#23However, reversing PROMPT_COMMAND so that "history -a" comes first makes more sense: this way the last command executed on the current terminal has a better chance of being on top of the list for the next up-arrow (which more closely resembles usual behavior).
Also, as noted above, it's better to append to PROMPT_COMMAND rather than just overwriting it. Thus, my .bashrc now reads:
export PROMPT_COMMAND="history -a; history -n;${PROMPT_COMMAND}"Re: Keeping bash history in sync between multiple terminals
#24A real trick would be keeping the bash history in sync between multiple machines.
Re: Keeping bash history in sync between multiple terminals
#25I always thought I wanted an in-sync bash history but after a few days of trying I realised it actually slowed me down. I have multiple terminals open (with Terminator, most of the time) and different windows / tabs are for different projects or tasks. If I'm building / configuring a project in 1 window, suddenly having a few apt-gets or log tails interspersed is very unproductive.
Yes, I found that too. It's convenient that up-arrow is context-specific. However, as a commenter on the blog said, the first suggestion avoids the "last logout wins" problem: shopt -s histappend
A good bash history can often save your behind when trying to reconstruct what you did or when you have to run that one magic command you last ran 5 months ago...
Re: Keeping bash history in sync between multiple terminals
#26I always thought I wanted an in-sync bash history but after a few days of trying I realised it actually slowed me down. I have multiple terminals open (with Terminator, most of the time) and different windows / tabs are for different projects or tasks. If I'm building / configuring a project in 1 window, suddenly having a few apt-gets or log tails interspersed is very unproductive.
If you typically use different terminal windows for different tasks (e.g. terminal #1 for compiling, terminal #2 for manpages, terminal #3 for vim, etc.), this will just clutter up your history with items unrelated to what your are doing.
Re: Keeping bash history in sync between multiple terminals
#27Earlier quoted context omitted.
That is brilliant! Care to point me toward a working implementation? :)
Sure -- here is the actual version from my dotfiles: https://github.com/aaronharnly/dotfiles-public/blob/master/.... (You can skip the stuff wrapping virtualenv, obviously.) Basically just define a function that does the write, set HISTFILE, read, and then elsewhere alias cd=mycd. If anyone gives it a try, I'd love to hear how it works! I think it needs some tweaks -- for example, multiple terminals in the same direc…
Re: Keeping bash history in sync between multiple terminals
#28Re: Keeping bash history in sync between multiple terminals
#29I use a tmux session on my server, so all I need is to log in from any computer and bring the session back up
Re: Keeping bash history in sync between multiple terminals
#30Don't overwrite the PROMPT_COMMAND like this, you risk breaking other tools such as autojump. Instead, append to it.