ksh implementation of pushd, popd, and dirs.

Tony Sanders sanders at peyote.cactus.org
Fri Feb 8 09:35:47 AEST 1991


Here are some csh functions I use converted to ksh (which I'm using now).
    # save directory
    function sd { pwd > $HOME/.dir/,$1 ; }
    # restore directory
    function rd { cd `cat $HOME/.dir/,$1` && pwd ; }

Be sure and run "mkdir $HOME/.dir"
Lets you save directories by name and cd back to them with
support for a default directory, which is nice if you run
X-windows and want to sync up all your windows you the same
directory (just run "sd" in one window and "rd" in all the rest).

This one is handy for programmers:
    alias vm='if [ -f makefile ]; then vi makefile; else vi Makefile; fi'
in csh I use:
    alias vm 'vi [Mm]akefile || vi Makefile'

These are handy for mh users:
    function v { vi `mhpath ${*-cur}`; }
    alias fll='folders @.'
    alias flr='folder -recurse'
    alias fls='folders @. -fast'
    alias pwf='mhpath'
    # cf makes folders look like directories:  cf /inbox; cf /news/comp/ai
    function cf { folder `echo "$*" | sed -e "s/^\//+/" -e "s/^[^+]/@&/"`; }

Here is my latest working creation:
function warp
{
    if [ $# = "0" ]; then
        echo "usage: warp warpid [params]"
        return 1
    fi
    # if [ -f "$HOME/.warp/@$warp" ]; then
    #   . "$HOME/.warp/@$warp" "$1"             # unwarp previous warp
    # fi
    warp="$1"; shift
    . "$HOME/.warp/$warp" "$@"
}

It's a front end to the '.' command (source for csh users).
I'm still working out all the details of how I want it to
work and if I should use the unwarp stuff and when.
Here is a sample warp file:
    if [ ! -f /SOMEDIRECTORY/rrn ]; then
	mount -t newsserverstuff
    fi
    . $HOME/.path			# set default path
    PATH=$PATH:/news/rsbin		# append news directory bin
    export PATH

I have other more complicated examples but I can't really post them.
I have two that setup build environments for different things and
automatically mount and unmount (unwarp) stuff when needed.

For now I unwarp by hand "warp @$warp" when I want.
My original idea was that unwarp would be called automatically when
you warp to something else (if it existed) but the I had the
problem of warping to A in two windows and then warping to B
in one of them.  I still wanted to use A in the first window
but it wanted to unmount my directories so I turned it off.
Maybe I need a refcount or something but that's too complex,
I want to keep it simple.

ideas/comments/suggestions welcome:

-- sanders at peyote.cactus.org
First rule of software:  Throw the first one away.
and so on...
For every message of the day, a new improved message will arise to overcome it.
IBM UUCP Path: cs.utexas.edu!ibmchs!auschs!sanders.austin.ibm.com!sanders
I am not an IBM representative and I speak only for myself.



More information about the Comp.unix.shell mailing list