prompt question

Brandon S. Allbery KB8JRR allbery at NCoast.ORG
Tue Feb 12 13:34:28 AEST 1991


As quoted from <dfs.665954950 at riker> by dfs at doe.carleton.ca (David F. Skoll):
+---------------
| In <51331 at sequent.UUCP> edw at sequent.UUCP (Ed Wright) writes:
| 
| >You can take that to a silly extreme
| >alias cd 'cd \!* ;set prompt=`hostname`" "`whoami`" "`pwd`" {\!} "'
| 
| I have taken my prompt to an even SILLIER extreme (but I like it.)  Here's
| an extract from my .cshrc:
> (deleted for brevity)
| This is what is looks like right now:
| 
| 	--> /enterprise/transporter/dfs <--
| 	2: dfs at riker(ttyp4)% 
+---------------

If you don't mind some ksh injected into this discussion:

case "$-" in
*i*)	typeset -i Level
	Level=${LEVEL:-0}
	Level=$Level+1
	LEVEL=$Level
	unset Level
	export LEVEL
	case $LEVEL in
	1)	level="" ;;
	*)	level="${LEVEL}@" ;;
	esac
	UID="`id|sed -n 's/^uid=\([0-9][0-9]*\)(.*$/\1/p'`"
	case "$UID" in
	0)	prompt='K#'
		;;
	204)	prompt='K$' ;;
	*)	prompt="`awk -F: '$3 == '$UID' {
				print \"{\" $1 \"}\"
				exit
			}' /etc/passwd` K$"
		;;
	esac
	PS1="${level}`uname -n`:! ${prompt} "
	unset prompt level
	;;
esac

This is actually an older version; my current version is driven off the login
name, but it's on a different machine.

The prompt, in both versions, looks like:

2 at ncoast:141 K$ _

("_" is the prompt, a convention of mine in messages which include interactive
shell stuff.)

"2@": 2nd level login; 141: command number; "K" to remind me it's Korn shell;
"$" because it's non-root.  Root gets "K#"; if I su to anyone else, I get:

2 at ncoast:142 {news} K$ _

The newer version also indicates the (compressed) tty and directory stack
depth, if it's not 1: 

2 at telotech[con/0]:143 (test) K$ pwd
/u/allbery
2 at ncoast[con/0]:144 (test) K$ pushd /tmp
/tmp /u/allbery
2+2 at ncoast[con/0]:145 (test) K$ _

The console is "con"; MultiView windows (a sort of "screen" which emulates the
real terminal instead of a VT102) are indicated as real-tty/windo-number
("con/0"); there is no [] if it's not running on a terminal-like fd (i.e. a
pipe).

The () is a project ID; it's omitted if I haven't set a project.  This is
usually a handier method of identifying a window than the window number.

(The directory stack is implemented via ksh functions, and includes most, if
not all, of the csh directory stack facilities.)

I tried including the current directory in the prompt, but it got too big too
fast; it's big enough as it is, and paths are generally a lot longer than the
other stuff I include.  And I detest two-line prompts.  Moreover, the project
ID is usually sufficient for my needs, since a project usually has a specific
directory associated with it.

++Brandon
-- 
Me: Brandon S. Allbery			    VHF/UHF: KB8JRR on 220, 2m, 440
Internet: allbery at NCoast.ORG		    Packet: KB8JRR @ WA8BXN
America OnLine: KB8JRR			    AMPR: KB8JRR.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery    Delphi: ALLBERY



More information about the Comp.unix.misc mailing list