home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume1 / bourne / part1 / aliases.sh next >
Encoding:
Text File  |  1986-11-30  |  1.0 KB  |  72 lines

  1. # aliases.sh --- sample shell functions which do some of what the csh does
  2.  
  3. # pushd, popd, and dirs --- written by Chris Bertin
  4. # Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
  5. # as modified by Patrick Elam of GTRI
  6.  
  7. pushd () {
  8.     SAVE=`pwd`
  9.     DSTACK="$SAVE $DSTACK"
  10.     if [ "$1" = "" ] 
  11.     then
  12.         if [ "$DSTACK" = "$SAVE " ]
  13.         then
  14.             echo "pushd: directory stack empty."
  15.             DSTACK=""
  16.             return 1
  17.         fi
  18.         set $DSTACK
  19.         cd $2
  20.         shift 2
  21.         DSTACK="$SAVE $*"
  22.     else
  23.         if (cd $1)
  24.         then
  25.             cd $1 >&-
  26.         else
  27.             popd > /dev/null
  28.             return 1
  29.         fi
  30.     fi
  31.     dirs
  32.     return 0
  33. }
  34.  
  35. popd () {
  36.     if [ "$DSTACK" = "" ] 
  37.     then
  38.         echo "popd: Directory statck empty"
  39.         return 1
  40.     fi
  41.     set $DSTACK
  42.     cd $1
  43.     shift
  44.     DSTACK=$*
  45.     dirs
  46.     return 0
  47. }
  48.  
  49. dirs () {
  50.     echo "`pwd` $DSTACK"
  51.     return 0
  52. }
  53.  
  54. xchng () {    # exchanged top two entries on the stack
  55.     if [ "$DSTACK" = "" ]
  56.     then
  57.         echo exchange directory stack empty
  58.         return 1
  59.     else
  60.         pushd
  61.         return 0
  62.     fi
  63. }
  64.  
  65. source () {    # have the shell read a file in the current shell
  66.     . $*
  67. }
  68.  
  69. bye () { logout ; }
  70.  
  71. logout () { exit 0 ; }
  72.