[mod.computers.vax] A Useful 'SET DEFAULT' Replacement

forrest@cgl.ucsf.edu@blia.UUCP (02/13/87)

The following is a command procedure that replaces the
'SET DEFAULT' command. There have been many versions
of such command procedures, including the one that
appeared in the Feb. 1987 issue of DEC Professional which
this one is based on. The primary feature of my version is that it
sets your prompt to the complete default directory name.
Best of all, unlike the VMS 'SET DEFAULT' command, my
command procedure prints an error message if you try
to set your default directory to a non-existent directory.
Finally, if you don't give it any arguments, it will set
your default directory to your login directory.

I use the name 'cd' to run to this procedure. Since I spend
my days logged in to both Unix and VMS, this makes my life
much easier. I hope it makes your easier too.

Jon Forrest
ucbvax!mtxinu!blia!forrest


$ on error then exit
$ if (p1 .eqs. "") then p1 = f$trnlog("sys$login")
$ old_dir = f$environment("DEFAULT")
$ set def 'p1'
$ dir = f$environment("DEFAULT")
$ if f$parse("''dir'") .eqs. "" then goto no_such
$ prompt = dir
$ set prompt = "''prompt' "
$ exit
$ no_such:
$ write sys$output "No such directory as ''dir'"
$ set def 'old_dir'

u3369429@seismo.CSS.GOV@murdu.OZ.AU (02/16/87)

In article <8702131859.AA01619@blia.BLI> forrest@cgl.ucsf.edu@blia.UUCP (Jon Forrest) writes:
>The following is a command procedure that replaces the
>'SET DEFAULT' command. There have been many versions
>of such command procedures, 
My hot favourite is "SD" by Richard L.Bryan, Stan Knutson, Vicki, Tom Kent
and Alan L. Zirkle. Beats everything I've seen so far.

>The primary feature of my version is that it
>sets your prompt to the complete default directory name.
Don't you get into difficulties if the length of your current directory string
is greater than 32 characters?

I use my prompt-string for two different things:
A "$$ " indicates that my privileges are switched on, a "# " indicates that they
are disabled.
When I also wanted to include the "current directory" in my prompt, I found it
very inconvenient to look for the cursor all over the screen. I like things to
be predictable. So I came up with a prompt string which displays the directory
on the far right, while the usual prompt ({"$$ "|"# "}) appears on the left.

The resulting procedure ("PCD") is called by my version of "cd" ("SD", see
above). Here it is:
 
$ Verify='F$Verify(F$TRNLNM("COMMAND_DEBUG"))
$! Procedure: PCD.COM  V-1.24  Michael Bednarek  November 1986
$! Sets prompt to Current Directory/CR/Previous Prompt
$! It produces a 32 character prompt string with the directory as far to the
$! right as possible, positioning the cursor however after the 'previous prompt'
$! This can result in a strange appearance with long directory names; never
$! mind, just type over it.
$ CR[0,8]=13					! Carriage Return
$ TAB[0,8]=9					! Horizontal Tab
$ Old_Prompt=F$Environment("Prompt")
$ pCR=F$Locate(CR,Old_Prompt)			! position of <CR> in Old_Prompt
$ If pCR.eq.F$Length(Old_Prompt) then pCR=-1
$ Prompt=F$Extract(pCR+1,255,Old_Prompt)	! part of Old_Prompt after <CR>
$ lP=F$Length(Prompt)				! length thereof
$ Directory=F$Environment("DEFAULT")
$ lD=F$Length(Directory)
$ If lP+lD.le.31 then goto Do_it
$! If the length of the part of OLD_Prompt that we want to retain (lP) plus
$! the length of the current directory is greater than 31 we extract the
$! rightmost part of the directory string.
$ x=31-lP
$ Directory=F$Extract(lD-30+lP,x,Directory)
$ lD=x
$ Do_it: n=31-lD-lP	! n indicates the number of <TAB>s we can insert
$ If n.lt.0 then n=0
$ If n*8+lD.gt.80 then n=(80-lD)/8	! but don't make it fall off the screen
$!Prompt=F$FAO("!''n'*	")+Directory+CR+Prompt
$ Prompt=F$FAO("!''n'*''TAB'")+Directory+CR+Prompt
$!
$ Set Prompt="''Prompt'"
$ Verify=F$Verify(Verify)

u3369429@murdu.oz.au (Michael Bednarek)