[comp.unix.questions] alias to link cd to pwd

phd_ivo@gsbacd.uchicago.edu (06/08/89)

A long time ago, I had a script that links a cd to
reset the prompt to the currently connected directory.

Unfortunately, I can't find it anymore, and my documentation
is not telling me how to delay the execution of `pwd` in something
like

	alias cd "cd \!^ ; set prompt=`pwd`"

Could someone please post a copy of such an alias, please? 
Incidentally, I am running a NeXT with Mach, a Berkeley 4.3BSD
variation without ksh but with csh.

Thanks. /ivo

mday@ohs.UUCP (Matthew T. Day) (06/09/89)

in article <3710@tank.uchicago.edu>, phd_ivo@gsbacd.uchicago.edu says:
> 
> 
> A long time ago, I had a script that links a cd to
> reset the prompt to the currently connected directory.
> 
> ...
>

Here's what I use, and it takes advantage of the built-in $cwd variable in
the Berkeley C-Shell, which drastically decreases the time needed to change
directories.  It also uses the 'chdir' alternative to avoid recursive aliases.
The SysV C-Shell that I used didn't have $cwd, so if yours doesn't, simply try
putting backslashes in front of the back "execution" quotes around `pwd`.

alias sp 'set prompt = "$cwd"\>\ '
alias cd 'chdir \!^; sp'

It works great, have fun.
-- 
+----------------------------------------------------------+-----------------+
| Matthew T. Day, Orem High School, Orem, Utah             | "He who laughs, |
| Internet: mday@ohs.uucp  UUCP: ..!uunet!iconsys!ohs!mday |  lasts."        |
+----------------------------------------------------------+-----------------+

iwarner@zaphod.axion.bt.co.uk (Ivan Warner,G44 SSTF,6632,) (06/09/89)

From article <3710@tank.uchicago.edu>, by phd_ivo@gsbacd.uchicago.edu:
 
> A long time ago, I had a script that links a cd to
> reset the prompt to the currently connected directory.
> 
> Unfortunately, I can't find it anymore, and my documentation
> is not telling me how to delay the execution of `pwd` in something
> like
> 
> 	alias cd "cd \!^ ; set prompt=`pwd`"
> 
> Could someone please post a copy of such an alias, please? 
> Incidentally, I am running a NeXT with Mach, a Berkeley 4.3BSD
> variation without ksh but with csh.
 

	Here's mine:

--------------------------------------------------------------------------
	alias cd '\!\! ; set prompt="! $cwd:t> "'
	alias pushd '\!\! ; set prompt="! $cwd:t> "'
	alias popd 'popd ; set prompt="! $cwd:t> "'
--------------------------------------------------------------------------

	This gives a prompt with the command number (useful for history
substitution) and the last component of the directory path (the tail).

	If you want the whole pathname in the prompt remove the `:t' after
the $cwd.


	Ivan Warner.

envbvs@epb2.lbl.gov (Brian V. Smith) (06/10/89)

In article <307@ohs.UUCP>, mday@ohs.UUCP (Matthew T. Day) writes:
>
> in article <3710@tank.uchicago.edu>, phd_ivo@gsbacd.uchicago.edu says:
> > A long time ago, I had a script that links a cd to
> > reset the prompt to the currently connected directory.
>
> Here's what I use, and it takes advantage of the built-in $cwd variable in
> the Berkeley C-Shell, which drastically decreases the time needed to change
> directories.  It also uses the 'chdir' alternative to avoid recursive aliases.
> The SysV C-Shell that I used didn't have $cwd, so if yours doesn't, simply try
> putting backslashes in front of the back "execution" quotes around `pwd`.
>
> alias sp 'set prompt = "$cwd"\>\ '
> alias cd 'chdir \!^; sp'
>
> It works great, have fun.

No, it doesn't. :-)

The trouble with the $cwd variable is that it doesn't know anything
about symbolic links (at least on Ultrix, SunOs 3.5, Sunos 4.0.1 or 4.2BSD).
So, if you cd to /usr/adm (for example) on a system where that is really a
symlink to /usr/var/adm,  $cwd will be equal to "/usr/adm", when the path
is really "/usr/var/adm."







_____________________________________
Brian V. Smith    (bvsmith@lbl.gov)
Lawrence Berkeley Laboratory
We don't need no signatures!

tale@pawl.rpi.edu (David C Lawrence) (06/10/89)

In <2801@helios.ee.lbl.gov> envbvs@epb2.lbl.gov (Brian V. Smith) writes:
> The trouble with the $cwd variable is that it doesn't know anything
> about symbolic links (at least on Ultrix, SunOs 3.5, Sunos 4.0.1 or
> 4.2BSD).  So, if you cd to /usr/adm (for example) on a system where
> that is really a symlink to /usr/var/adm, $cwd will be equal to
> "/usr/adm", when the path is really "/usr/var/adm."

% set hardpaths

This works on all cshs that know about the hardpaths variable, among
them the csh that comes with SunOS.  It also applies to pushed
directories listed with "dirs".

Some people like the fact that the name of the symlink is used rather
than the hardpath.  I don't, but since it can be done either way, so
what?

Dave
--
 (setq mail '("tale@pawl.rpi.edu" "tale@itsgw.rpi.edu" "tale@rpitsmts.bitnet"))
  "I realize the Internet isn't the whole world, but it is the center of it."
                                                        -- Greg Woods

envbvs@epb2.lbl.gov (Brian V. Smith) (06/10/89)

In article <TALE.89Jun9140925@imagine.pawl.rpi.edu>, tale@pawl.rpi.edu (David C Lawrence) writes:
> In <2801@helios.ee.lbl.gov> envbvs@epb2.lbl.gov, I wrote:
> > The trouble with the $cwd variable is that it doesn't know anything
> > about symbolic links (at least on Ultrix, SunOs 3.5, Sunos 4.0.1 or
> > 4.2BSD).  So, if you cd to /usr/adm (for example) on a system where
> > that is really a symlink to /usr/var/adm, $cwd will be equal to
> > "/usr/adm", when the path is really "/usr/var/adm."
> 
> % set hardpaths
> 
> This works on all cshs that know about the hardpaths variable, among
> them the csh that comes with SunOS.  It also applies to pushed
> directories listed with "dirs".
> 
> Some people like the fact that the name of the symlink is used rather
> than the hardpath.  I don't, but since it can be done either way, so
> what?

You are right.  This works on SunOs systems.  Unfortunately, DEC is still 
behind the times and it doesn't work on Ultrix (3.0)

_____________________________________
Brian V. Smith    (bvsmith@lbl.gov)
Lawrence Berkeley Laboratory
We don't need no signatures!



























This is a trailer so that xrn will post this even though I have less text
than the included text.  I have to fix that!

pcash@cxhq.UUCP (Peter Cash) (07/20/89)

In article <3710@tank.uchicago.edu>, phd_ivo@gsbacd.uchicago.edu writes:
> 
> A long time ago, I had a script that links a cd to
> reset the prompt to the currently connected directory.
...
> Could someone please post a copy of such an alias, please? 

I use the following solution:

# in .profile:

alias cd=c
. .functs

# in a separate file called ".functs":

c() { cd $1; PS1="`tput smso``pwd`:`tput rmso`
"; }

This prints the prompt as inverse video, and gives me an entire
line on which to enter long commands.  (This can be handy if the
cwd is long, also...)


Peter