Live data from Hacker News

Keeping bash history in sync between multiple terminals

briancarper.net

31–35 of 35 posts

Re: Keeping bash history in sync between multiple terminals

#31
post #26

I 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.

I am going to chime in with a similar sentiment. I also had bash configured like this for awhile when I realized it is not what I wanted. 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.

Granted. But then if tomorrow you do want a record of what you did in terminal 2 today? Multiple histories?

Re: Keeping bash history in sync between multiple terminals

#32

Don't overwrite the PROMPT_COMMAND like this, you risk breaking other tools such as autojump. Instead, append to it.

How?

This is how autojump does it:

    export PROMPT_COMMAND="$AUTOJUMP ; ${PROMPT_COMMAND:-:}"

Re: Keeping bash history in sync between multiple terminals

#34

Earlier quoted context omitted.

This is how autojump does it: export PROMPT_COMMAND="$AUTOJUMP ; ${PROMPT_COMMAND:-:}"

My bash-fu is weak; can you break that down for me?

${VARIABLE:-value} expands to the contents of $VARIABLE, if it exists, or to "value" otherwise. In this case value is ":", a bash builtin that does nothing. Effectively, the above sets PROMPT_COMMAND to run the autojump command, then to run the pre-existing PROMPT_COMMAND, if any, or a no-op.

Re: Keeping bash history in sync between multiple terminals

#35
I really like the "ctrl + o" trick mentioned in the third comment: "Normally, if you enter a series of commands, you can go back to the first one, and hit Ctrl-O repeatedly to run the current command and retrieve the next."

Found a description here: http://www.halotis.com/2010/07/06/bash-keyboard-shortcuts/

Post reply on HN