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 |
It works! |
No comments:
Post a Comment