bash enhancements: history
Peter
plp-ysDPMY98cNQDDBjDh4tngg at public.gmane.org
Wed Jun 1 21:13:59 UTC 2005
I had proposed that various instances of bash exit and save their
respective histories in the ~/.bash_history file. I think that I found a
way to do this (error checking omitted in code below):
fd = open( "~/.bash_history", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR );
flock( fd, LOCK_EX );
append_history( history_length, "~/.bash_history" );
flock( fd, LOCK_UN );
close( fd );
this is simple enough to patch into bash, no ? (is this use of flock
safe ? what if append_history uses flock() itself ?) The issue of
identifying the instance in the saved history list is not addressed. It
could be addressed by adding a log entry like:
now = time();
sprintf( buf, "# %s: bash(%d) exiting", ctime( &now ), getpid() );
add_history( buf );
before running the code above. When loaded in the history of a next
instance it would appear as a comment line and do nothing if recalled by
mistake. A similar entry could be added to the history when the shell
starts (immediately after using_history(); ), with the effect of
bracketing the commands used by a certain instance.
Peter
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list