[Cialug] How to add multiple instances of bash to your bash history

Jeff Chapin chapinjeff at gmail.com
Thu Mar 20 16:10:09 CDT 2014


/me raises hand

I'm interested.


On Thu, Mar 20, 2014 at 3:09 PM, Tim Wilson <tim_linux at wilson-home.com>wrote:

> I chose a different way of doing things.  I tend to do specific things in
> specific windows.  Compile in one, look at source in another, run an
> application in yet another.  For me, having co-mingled histories just
> wouldn't work.  So I have it set up so that every window I open in X starts
> a login shell, which runs my .bash_profile.  In .bash_profile, I have the
> following:
> NEWWINDOW=1
> LOGTTY=${LOGTTY:=`tty`}
> my_tty=${LOGTTY#/dev/pty}
>
> Then in my .bashrc:
> if [[ ${NEWWINDOW:-0} -ne 0 && $my_tty != "not a tty" ]]; then
>     export THISWIN=$my_tty
>     typeset -i THISWIN
>     export HISTFILE=$HOME/.histories/.bash_hist.$THISWIN.0
>     export HISTSIZE=512
>     unset NEWWINDOW
> fi
>
> This way, when I open that window again, I have the same history I did
> before.  I take things a bit further by having a history per shell.  That
> is, if I shell out of vi, I have a different history file.  That gets a bit
> convoluted, so I'm not showing that here.  Also, for larger machines with a
> lot of users, the ttys aren't going to be 1,2,3, etc.  Instead, I employ a
> scheme of touch'ing a file in a directory to keep track of the number of
> windows I've opened.  When I close a window, a trap call is executed to
> remove the file.  I iterate through the files to see if there's an
> opening.  So if I open 3 windows, close the 2nd one, and re-open it, I get
> the same history, even though the tty could be way different.  If anyone is
> interested in that, I can include that too.
>
>
>
> On Wed, Mar 19, 2014 at 11:55 PM, Adam Hill <adam at diginc.us> wrote:
>
> > Here is my standard history setup from ~/.bashrc
> >
> > export HISTSIZE=100000
> > export HISTFILESIZE=50000
> > export HISTCONTROL=ignoredups
> > export PROMPT_COMMAND="history -a; history -n; $PROMPT_COMMAND"
> >
> > the -a submits your recent commands so other sessions see them, the -n
> > pulls the hitsory back into your session so you can see your other
> > sessions' history.
> >
> >               -a     Append  the  ''new'' history lines (history lines
> > entered
> >                      since the beginning of the current bash session)  to
> >  the
> >                      history file.
> >               -n     Read  the history lines not already read from the
> > history
> >                      file into the current  history  list.   These  are
> >  lines
> >                      appended  to  the history file since the beginning
> of
> > the
> >                      current bash session.
> >
> > You still usually have to press return once to see your other session's
> > histories but it works great besides that little quirk
> >
> >
> >
> >
> > On Wed, Mar 19, 2014 at 8:35 PM, Andrew Denner <linux-list at upeke.com>
> > wrote:
> >
> > > As was discussed at the meeting tonight, by default bash only writes
> the
> > > last bash session running to the history blowing away any other
> > instances.
> > > Per
> > >
> >
> http://www.aloop.org/2012/01/19/flush-commands-to-bash-history-immediately/
> > >
> > > If you add: "export PROMPT_COMMAND='history -a'" To your .bashrc file
> it
> > > will append each command immediately to your bash history file
> > >
> > > On Tuesday, March 18, 2014, Barry Von Ahsen <vonahsen at gmail.com>
> wrote:
> > >
> > > > screen vs. tmux vs. byobu
> > > >
> > > > 7pm at Alliance
> > > >
> > > > http://www.cialug.org/?page_id=7&event_id=1030
> > > > _______________________________________________
> > > > Cialug mailing list
> > > > Cialug at cialug.org <javascript:;>
> > > > http://cialug.org/mailman/listinfo/cialug
> > > >
> > > _______________________________________________
> > > Cialug mailing list
> > > Cialug at cialug.org
> > > http://cialug.org/mailman/listinfo/cialug
> > >
> > _______________________________________________
> > Cialug mailing list
> > Cialug at cialug.org
> > http://cialug.org/mailman/listinfo/cialug
> >
>
>
>
> --
> Tim
> Required reading: http://bccplease.com/
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
>



-- 
Jeff Chapin
President, CedarLug, retired
President, UNIPC, "I'll get around to it"
President, UNI Scuba Club
Senator, NISG, retired


More information about the Cialug mailing list