How to save shell history more conveniently in tcsh?

3

I'm using tcsh quite extensively and have several questions about it's history:

  • Is there a way to save commands for different shell tabs separately?
  • Is there a way to save commands by session (for cases like this: ssh otheruser@othercomputer)?
  • Can I add dates to the shell history? (I know this can be done in bash)

White Zebra

Posted 2012-05-06T14:48:28.300

Reputation: 33

This helped me solve the dates issue. – White Zebra – 2012-05-15T16:25:54.593

Answers

1

There isn't a built-in method of saving saving the command history separately or by session. You would have to set your 'histfile' variable on a per-instance basis. This means you would need something unique in your environment that is present already when your .tcshrc file is sourced, or add code to yourself to the very top of your .tcshrc that finds some unique value, perhaps from the tty command.

Take care to only do this when you're in an interactive shell so that it won't unnecessarily slow down or complicate other things that spawn new tcsh shells that you might not expect. For example, if you're using vim and you execute any shell commands, the tty command won't behave.

I usually use the prompt3 method...

if ( $?prompt3 ) then
    #
    # interactive-only things...
    #
endif

For a separate history, might be able to get away with something like:

set mytty = ( `tty` )
set histfile = ( ".history.${mytty}" )

Andrew Harrison

Posted 2012-05-06T14:48:28.300

Reputation: 156