rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
From: "Paul D. Swasey" <ps3u+@andrew.cmu.edu>
To: rc@archone.tamu.edu
Subject: 'cd -'
Date: Tue, 17 Dec 1991 02:15:24 -0600	[thread overview]
Message-ID: <Added.EdHP_JC00UkT8Csk4V@andrew.cmu.edu> (raw)

Here is a simple way to get the effect of kshes 'cd -', it costs an
extra line per cd command in your $history but it only costs one
variable (the current directory cache) and one call to "pwd", when
leaving the current directory (if the current directory is not $home).

(it's nice for me because I do "pwd" a lot, anyway, so "cd" only has
to calculate the current directory about half the time...)

sample:
peso ; pwd
/afs/andrew.cmu.edu/system/src/contributed/niftylibs/017/util
peso ; cd
peso ; - cd
cd /afs/andrew.cmu.edu/system/src/contributed/niftylibs/017/util
peso ; tail -7 $history
pwd
cd
cd /afs/andrew.cmu.edu/system/src/contributed/niftylibs/017/util
- cd
cd /afs/andrew.cmu.edu/system/src/contributed/niftylibs/017/util
cd /afs/andrew.cmu.edu/usr16/ps3u
tail -7 $history
peso ;

er, make that 2 extra lines per cd command (i forgot about the one
added by -(1) )

-dave
-----
fn cd {
        builtin cd $1 && {
		if (!~ $history ())
			echo cd `pwd >>$history
		switch ($1) {
		case ()
			PWD=$home
		case *
			PWD=()
		}
	}
}
fn pwd {
        if (~ $PWD ())
		PWD=`{builtin pwd}
        echo $PWD
}


                 reply	other threads:[~1991-12-17  8:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Added.EdHP_JC00UkT8Csk4V@andrew.cmu.edu \
    --to=ps3u+@andrew.cmu.edu \
    --cc=rc@archone.tamu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).