Getting UNIX prompt to display curr

Rouben Rostamian rostamia at umbc3.UMBC.EDU
Wed Mar 22 15:15:28 AEST 1989


Here are a couple of sicko aliases that set the prompt to the current
directory.  The first:

alias cd cd \!\*\; set prompt = \
  pwd \| awk \'BEGIN \{FS=\"/\"\} \{print \$\'NF\'\}\'\`\"\> \"

causes "cd" to change directory and set the prompt to "thisdir> ",
where "thisdir" is the name of the current directory only, *not* its full
pathname.

The second:

alias asdf cd \!\*\; set prmpt = \`pwd \| awk \'BEGIN \{FS=\"/\"\} \
       \{cnt = NF\; cnt -- \; \
        printf \"\%-1s/\%-1s\>\", \$\'cnt\', \$\'NF\' \}\'\` \; \
        set prompt = \"\$prmpt \"

 causes "cd" to change directory and set the prompt to
"parentdir/thisdir> ", where "parentdir" is the name of the parent
directory of the current directory.

These definitions are mildly machine-dependent.  As they are, they both
work in Ultrix.  When I tried them on an Ardent Titan running System V,
I had to add a semicolon after the BEGIN{...} statements.
(If you are really going to make the change, you should 
insert a \; after the closing brace of each BEGIN{...} statement.
 
P.S.1:  I do not use these aliases myself -- I would rather stick to
a fixed, well-chosen, pre-defined prompt and do 'pwd' when I forget where
I am in the directory tree.

P.S.2:  Someone posted a solution recently for making the prompt the 
*full* pathname of the current directory.  The solutions above
were inspired by that posting.

P.S.3:  To those people who continue flaming about frequent and repeated 
postings of elementary questions in this news group:  Short of starting
a comp.unix.questions.elementary, if the answer to the 
question is really short and simple, please just post it and let it
go at that.  More boring than silly questions are flames about silly 
questions. 

-- 
Rouben Rostamian
Department of Mathematics                      e-mail:
University of Maryland Baltimore Counnty       Rostamian at umbc2.bitnet
Baltimore, MD 21228                            rostamia at umbc3.umbc.edu



More information about the Comp.unix.questions mailing list