From: STUBRBEE@EKU.BITNET (Oooooooops)
Newsgroups: comp.os.vms
Subject: Re: Is it possible for set prompt to do this?
Date: 8 Sep 92 18:07:18 GMT
Distribution: world
Organization: The Internet

Dude,
     I'm not user exactly what your asking but this is what I got from it.  You
want your prompt to be what directory your in.  I got this program off the net
and modified it for my own personal needs.  It allows unix style and vax type
directory changing (cd duh , cd [.duh]) and logicals and such.  The only
problem is if you don't use this program to change directories it won't know
you have changed so the prompt will be wrong.  But take a view at this...
Please not the logical settings of CD$PROMPT and CD$LOG!

$!
$!  This program will do *ALL* the following:
$!
$!  cd                  Move you to your home directory
$!  cd subdirectory     Move down to that subdirectory
$!  cd ~                Move you to your home directory
$!  cd ~/subdir         Move you to subdirectory 'subdir' off home directory
$!  cd ~user            Moves to home dir of user.  You will need to define
$!                      a logical "cd$user" to point to the device(s) and
$!                      directory containing users.
$!  cd dua0:[dir]       Also accepts VAX format
$!  cd logical:         Moves to the dir pointed by logical.  If
$!                      there is a ":" at the end and it's not a
$!                      logical, then it will be treated as a device.
$!  cd ..               Goes up a directory level
$!  cd ..../directory   Goes up 3 directory levels and then down to
$!                      directory, as in UNIX cd ..../directory
$!  cd sub1/sub2/sub3   Go down three levels of directories
$!  cd sub1.sub2.sub3   Same as above.  "." and "/" are interchangable except
$!                      that "/" can NEVER be the first char after <cd>.
$!  cd >name            Creates a logical 'name' whose value is the current
$!                      directory which you can later use to: 'cd name:'
$!
$!  If the Logical CD$,PROMPT == "YES" then this program will make
$!  the users prompt show the current directory.
$!
$!  If the Logical CD$LOG == "YES" then this program will show the
$!  directory before exiting a la <show default>.
$!
$ If f$length(p1) .gt. 0 then If f$Trnlnm(p1) .nes. "" then p1 = p1 + ":"
$ If F$Length(p1) .eqs. 1 Then If p1 .eqs. "/" then p1 = F$TRNLNM("Sys$Login")
$!
$ if f$ext(0,1,p1) .nes. ">" then goto normal_change_dir
$ newlogical = f$ext(1,99,p1)
$ if newlogical .eqs. "" .and. p2 .nes. "" then newlogical = p2
$ currdir = f$parse("[]") - ".;"
$ define 'newlogical' 'currdir'
$ exit
$normal_change_dir:
$ uname = f$trnlog("SYS$LOGIN")
$ if p1 .eqs. "" then p1 = uname
$ dir = p1
$ if f$ext(f$len(dir)-1,1,dir) .nes. ":" then goto nological
$ test = f$trnlog(f$ext(0,f$len(dir)-1,dir))
$ if test .nes. "" then dir = test
$ goto change
$nological:
$ if f$ext(0,1,dir) .eqs. "." then goto dot
$ if f$ext(0,1,dir) .eqs. "~"
$    then
$    if f$ext(1,1,dir) .eqs. "/" .or. f$len(dir) .eq. 1 then $ goto home_dir
$    dir = "cd$user:[''f$ext(1,99,dir)']"
$ endif
$ if f$ext(f$len(dir)-1,1,dir) .nes. "]" then dir = "[." + dir + "]"
$ goto unix_to_vax
$dot:
$ path = "["
$ dir = f$ext(1,99,dir)
$count_dots:
$ if f$ext(0,1,dir) .nes. "." then goto go_on
$ path = path + "-"
$ dir = f$ext(1,99,dir)
$ goto count_dots
$home_dir:
$ path = uname - "]"
$ dir = f$ext(1,99,dir)
$go_on:
$ if f$ext(0,1,dir) .eqs. "/" then dir = f$ext(1,99,dir)   !strip first "/"
$ if dir .nes. "" then dir = "." + dir
$ dir = path + dir + "]"
$unix_to_vax:
$ pos = f$locate("/",dir)
$ if pos .eq. f$len(dir) then goto change
$ dir = f$ext(0,pos,dir) + "." + f$ext(pos+1,99,dir)
$ goto unix_to_vax
$change:
$ if f$parse(dir) .eqs. "" then goto no_such
$ set def 'dir'
$ if F$TRNLNM("cd$prompt") .nes. "YES" then goto log
$ node = f$trnlnm("sys$node","lnm$system")-"::"+"!"+dir-"["-"]"
$ prompt = f$edit(node,"LOWERCASE")
$ If F$length(prompt) .gt. 30
$   Then
$     prompt = "*" + F$Extract(f$Length(prompt)-29,29,prompt)
$ EndIF
$ set prompt = "''prompt'> "
$log:
$ if F$TRNLNM("cd$log") .eqs. "YES" Then Write Sys$Output F$Env("default")
$ exit
$no_such:
$ dir = f$parse(dir,,,,"syntax_only") - ".;"
$ write sys$output "cd: directory ''dir' does not exist."
$ exit

{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}
{ Name         : David Barbee                  Aliases  : Sybie                }
{ Bitnet       : STUBRBEE@EKU                  Internet : I wish!              }
{ Disclaimer   : Listen to me?!?  Can't imagine why.                           }
{ Last Words   : Oh *beep*!  (Censored for our more sensitive readers)         }
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}
 ssss y   y b     i eeeee  '  ssss   u   u ttttt i l     i ttttt i eeeee  ssss
s      y y  b     i e      ' s       u   u   t   i l     i   t   i e     s
 sss    y   bbbb  i eee   '   sss    u   u   t   i l     i   t   i eee    sss
    s   y   b   b i e            s   u   u   t   i l     i   t   i e         s
ssss    y   bbbb  i eeeee    ssss     uuu    t   i lllll i   t   i eeeee     s
                                                                            s
ssssssssssssssssssssssss Programmer: David Barbee sssssssssssssssssssssssss