History from all shell sessions is less useful than I hoped!
I enthusiastically set PROMPT_COMMAND='history -a; history -r'
in the hopes that my history usage would be much better!
Wow, was I disappointed.
Essentially, doing this makes up/dn arrow useless. Because now each history session is littered with commands from other sessions. And for me this loses the best feature of history.
What I really wanted
Occasionally, I wanted to essentially transfer my history from one terminal session to another session so I could easily recall commands from that session. And I can do this very selectively.
What I did
I set up a series of simple history manipulation aliases & I ignore these commands in the history:
alias ha="history -a"
alias hb="history -a; history -r"
alias hr="history -r"
alias hl="history | tail -20"
HISTIGNORE="ha:hb:hr:hl"
I think of hb
as history blend...the others are self-explanatory.
Now when I want to copy my history from session A to session B, I can do this:
- A:
ha
- append session A history to history file
- B:
hb
- append session B history to history file and then read the file
This essentially preserves the history order for session B and adds session A history deeper in the list.
Super useful for me. Maybe helps you too!