Tuesday, November 6, 2012

V7/x86: Adding the current subdirectory to the prompt

The .cshrc script for the C shell in default guest account in V7/x86 is pretty spare. One of the first things I wanted to change after switching over to C shell is the prompt. I'd like the prompt to display the current subdirectory as I navigate the file system.

I want to go from this:

% cd src
%

To something like this:

/usr/guest% cd src
/usr/guest/src% 

The Unix V7 "pwd" command returns the current directory path. We can use this in our .cshrc script to include it's output in the prompt.

% pwd
/usr/guest
%

A great reference that helped me figure this out is the Unix FAQS at http://www.cs.albany.edu/~wuye/unixfaqs.html

Open .cshrc with the "vi" editor and move to the bottom of the file. Add the following text and save.

# add the current directory path to the prompt
alias setprompt 'set prompt="`pwd`% "'
setprompt
alias cd 'chdir \!* && setprompt'

The "alias" command gives us to create a new command that is composed of other commands. We've created the command "setprompt" so that we can use it twice without accidentally changing it between each use.

On the next line we call "setprompt" to display the current path when we login.

On the third line, we create a new alias for the "cd" command that will change the directory and reset the prompt to include the changed directory path.

Editing the .cshrc script
Logout and log back in and you'll see the following:

It works!


No comments:

Post a Comment