Stairways Software Icon

Stairways Software

Excellence In Software For Over Twenty Years – Only with a Mac

Remembering the path with tcsh in Terminal/Lion

In Lion, the new version of Terminal remembers your Windows and Tabs, including your scroll history, and with bash, also your path. If you use tcsh (as I have for 20 years or so), then it does not remember your path - here is how to fix it.

A little digging finds that bash sets this up in /etc/bashrc, specifically with update_terminal_cwd which it adds to PROMPT_COMMAND. It is careful to only do this for Apple_Terminal and while not inside Emacs. Since I don't use any other terminals (except TouchTerm on my iPhone) and I don't use Emacs, I've ignored that, but keep in mind there may be cases you need to disable this.

The trick is done by outputting a URL in an escape sequence.

In tcsh, you can set an alias to a command that is run immediately before printing your path, so you can set it to print the magic escape sequence using something like this:

alias precmd ~/perl/update_terminal_cwd.pl

update_terminal_cwd.pl duplicates the behaviour of update_terminal_cwd in /etc/bashrc:

#!/usr/bin/perl

my $pwd = $ENV{PWD};
$pwd =~ s! !%20!g;
$pwd = "file://$ENV{HOSTNAME}$pwd";
printf( "\e]7;%s\a", $pwd );

Add the alias to you .login and Terminal will remember your paths in tcsh too.

Posted Sunday, August 7, 2011. Permalink. Post a Comment.

Comments

Post Comment

Name: (optional)
URL: (optional)
Email: (optional, not published)
   
CAPTCHA: four nine three seven (required)
  To prove you are human, please enter the number as digits (ie, 1-9).
Comment:
  You can use some HTML tags such as <b>, <i>, and <a href="">.
We reserve the right to remove any offensive or inappropriate comments.
Due to spam issues, comments are initially invisible until we review them,
you can see them (background red) and we can see them, but no one else.

Comment Preview

None yet.

Buy Now

User Database

Stairways