Directory as Prompt String

cottrell at NBS-VMS cottrell at NBS-VMS
Thu Mar 21 09:45:05 AEST 1985


/*
[ jpage at rruxe.uucp wants to set PS1 in [k]sh when he does 'cd' ]
Perhaps this is a good time to repost an earlier article, as I didn't
receive as much comment as I liked. The lack of aliases & history in 
'sh' is most disturbing. It all started when I read the BSTJ article by
Kernighan & Pike (got it right this time!) that bemoaned the 
multiplicity of options on 'cat', Berkeley 'ls', & then went on to
attack the history mechanism of 'csh' as being specific only to 'csh' &
not working for ALL input, including programs invoked by [c]sh. After
fuming at the authors willingness to trade off useful features for
abstract purity, I did some thinking, and came up with the following
bizarre ideas.

Write a program (prog) which copies its stdin to stdout unless certain
escape characters (which implement history, aliases, local cmd editing,
anything else you want). Type 'prog | sh -i'. Whenever 'prog' sees the
user type 'cd <anything>\n' it stuffs ';PS1="`pwd` %' before the '\n'.
Thus, the prompt is always the current directory!

This will work MOST of the time, but there are exceptions. VI will not
work unless its stdin is a tty. Therefore, our prog must intercept any
references to VI (or any other uppity interactive program), fork & exec
it itself after redirecting stdin back to the tty.

There are other things that might be done, such as saving/restoring all
stty modes before/after any such interactive program executes, forking
the subshell directly from prog, always running in cbreak mode, etc.

Please note that this is SYS V we're talking about. No pseudo tty's
are available. Now that the cat's out of the bag, let's talk about
ways to skin it. What else does 'prog' have to watch out for?

	jim		cottrell at nbs
*/



More information about the Comp.unix.wizards mailing list