*BSD News Article 53938


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!swidir.switch.ch!in2p3.fr!univ-lyon1.fr!jussieu.fr!hookup!news.mathworks.com!solaris.cc.vt.edu!news.seanet.com!news.seanet.com!michaelv
From: michaelv@MindBender.HeadCandy.com (Michael L. VanLoon)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: DOS Style shell prompt
Date: 02 Nov 1995 05:58:10 GMT
Organization: HeadCandy Associates... Sweets for the lobes.
Lines: 65
Message-ID: <MICHAELV.95Nov1215814@MindBender.HeadCandy.com>
References: <814126352.7670@kiss.demon.co.uk> <466bek$l5r@agate.berkeley.edu>
	<46alsh$gil@uriah.heep.sax.de> <46brjo$p1l@mark.ucdavis.edu>
	<472nqf$6si@awfulhak.demon.co.uk>
NNTP-Posting-Host: mindbender.seanet.com
In-reply-to: brian@awfulhak.demon.co.uk's message of 30 Oct 1995 14:34:55 -0000

In article <472nqf$6si@awfulhak.demon.co.uk> brian@awfulhak.demon.co.uk (Brian Somers) writes:

   David E. O'Brien (obrien@cs.ucdavis.edu) wrote:

   : Just wanted to get my favorate one in (bash):
   : if [ "$PS1" != "" ]; then	# this shell is interactive
   : # for PWD to use ``~'' rather than $HOME in bash use: PS1=\h:\w"> "
   : if [ "$EUID" = "0" ]; then
   : 	PS1="\h(root):"'${PWD}'"> "
   : else
   : 	PS1="\h:\w> "
   : fi
   : fi # interactive

   Bash also allows '\$' which expands to '$' or '#' depending on uid.

   : for Zsh I use this:
   :     PS1=$HOSTNAME':%~> '

While we're on the subject, my tcsh prompt (attributes are %x, where x
is the specifier -- in the case of %c3, the 3 says to show the last 3
pieces of my cwd):

set prompt='[%B%n%b@%B%m%b]%B%c3%b%# '
              ^ ^ ^  ^ ^ ^  ^ ^  ^ ^
              | | |  | | |  | |  | +- print '>' for user or '#' for root
              | | |  | | |  | |  +--- stop boldface
              | | |  | | |  | +------ print last three parts of path
              | | |  | | |  +-------- start boldface
              | | |  | | +----------- stop boldface
              | | |  | +------------- print first "word" of hostname
              | | |  +--------------- start boldface
              | | +------------------ stop boldface
              | +-------------------- print username
              +---------------------- start boldface

Looks like this (without the bold) when I'm in, for example,
/sys/arch/i386/conf, on MindBender.HeadCandy.com:

	[michaelv@MindBender]arch/i386/conf>

And this in my home dir:

	[michaelv@MindBender]~>

My root prompt is similar:

set prompt='[%Sroot%s@%B%m%b]%B%c3%b%# '

The difference is that %S starts reverse video, and %s stops it (I
want to be *sure* I notice at a glance that I'm root).

I also like having the hostname in there because when I was
sysadmin-ing at Iowa State, it could be common for me to be remotely
logged into more workstations at once than you could count on a hand
or two.

--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Michael L. VanLoon                                 michaelv@HeadCandy.com
       --<  Free your mind and your machine -- NetBSD free un*x  >--
     NetBSD working ports: 386+PC, Mac 68k, Amiga, HP300, Sun3, Sun4,
                           DEC PMAX (MIPS), DEC Alpha, PC532
     NetBSD ports in progress: VAX, Atari 68k, others...
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -