I usually have multiple bash sessions open. I want the history from multiple session to appear when doing a search (with Ctrl + R). When arrow keys are used only the current bash session's history should appear.
Many stackexchange questions relates to storing the history from multiple session. I already use it but my need is little different.
Best Answer
First off, there is not a clean solution to your problem without reimplementing some key component of how the shell (bash in this case) deals with history. Below is a solution that maintains your local history so that the arrows work as expected. Ctrl-r in turn is bound to searching your global history. The solution depends on an excellent utility for searching through your history called hh. Below are the instructions to set everything up.
Add to a startup file either
~/.profile
,~/.bash_profile
or~/.bashrc
:Create the following script
~/swap_history_reverse.sh
:Make the script executable:
Install
hh
, see INSTALL.Once everything is in place, open up a new shell and give it a run.