Save command history from multiple shells

Apr 04, '02 09:58:46AM

Contributed by: bonkers

So I was setting up my multiple windows in the Terminal according to this article on O'Reilly's site (upon searching Mac OS X Hints, I found similar tips 1 & 2). Everything was looking and acting great. I created three windows that would open up when I launched Terminal (one for man pages, one for working, and one for misc commands).

Now as long as each window remained open, that window had its individual command history. However, when I logged out of all my windows individually and either restarted Terminal or opened a new terminal window I found that the majority of the commands I had used in all of the windows were NOT saved. As I did some testing I found that only the command history of the last window I logged out of was saved to .tcsh_history. After some reading of the man page for tcsh (shudder), I came up this little nugget of information:

history -S|-L|-M [filename] (+)

With -S, the second form saves the history list to filename. If the first word of the savehist shell variable is set to a number, at most that many lines are saved. If the second word of savehist is set to 'merge', the history list is merged with the existing history file instead of replacing it (if there is one) and sorted by time stamp (+). Merging is intended for an environment like the X Window System with several shells in simultaneous use. Currently it succeeds only when the shells quit nicely one after another.
So off to my .tcshrc file where I entered set savehist = (50 merge). Voila! Now the last 50 commands from all the windows are saved.

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020404095846769