* more rc code
@ 1991-07-18 14:21 Arnold Robbins
0 siblings, 0 replies; only message in thread
From: Arnold Robbins @ 1991-07-18 14:21 UTC (permalink / raw)
To: rc
Here is my .rcrc. The main thing is does is provide ksh-like cd
functionality. (In ksh, `cd -' goes back to the last directory
you were in. `cd old new' is roughly the same as
cd `{ pwd | sed s/old/new/ }
I tried in this version to be efficient, and only run external
programs where necessary.
Arnold
-------------------
# .rcrc --- start up procedure for rc
prompt=(`hostname ^ '% ' '> ')
# another emulation so that my fingers don't have to think
fn type { builtin whatis $* }
# cd.rc --- souped up version of cd
# this is designed to emulate the fancy version of cd in ksh,
# so if you're a purist, feel free to gag
_cwd=$home
_oldcwd=$home
fn cd {
if (~ $#* 0) {
if (~ $_cwd $home) { # do nothing
} else {
builtin cd && { _oldcwd=$_cwd ; _cwd=$home }
}
} else if (~ $#* 1) {
if (~ $1 -) {
_t=$_cwd
builtin cd $_oldcwd && {
_cwd=$_oldcwd
_oldcwd=$_t
echo $_cwd
}
_t=()
} else {
# if a cd happens through the cdpath, rc echos
# the directory on its own. all we have to do
# is track where we end up
_dopwd = 1
{ ~ $1 /* } && _dopwd = 0 # absolute path
builtin cd $1 && {
_oldcwd=$_cwd
_cwd=$1
{ ~ $_dopwd 1 } && _cwd=`/bin/pwd
}
_dopwd=()
}
} else if (~ $#* 2) {
_t=`{ echo $_cwd | sed 's<'$1'<'$2'<' }
builtin cd $_t && {
_oldcwd=$_cwd
_cwd=$_t
echo $_cwd
}
_t=()
} else {
echo cd: takes 0, 1, or 2 arguments >[1=2]
builtin cd $1 && { _oldcwd=$_cwd ; _cwd=`/bin/pwd ; echo $_cwd }
}
}
fn pwd { echo $_cwd }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1991-07-18 14:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-07-18 14:21 more rc code Arnold Robbins
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).