Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Directory Prompt
@ 1996-04-25  4:00 dhinkle
  1996-05-04  4:00 ` Martin Hannigan
  1996-05-09  4:00 ` Ken Brown
  0 siblings, 2 replies; 13+ messages in thread
From: dhinkle @ 1996-04-25  4:00 UTC (permalink / raw)



Does anyone know how to make the c shell display the current directory
in the prompt, and change the prompt as you change directories.

Digital Unix 3.2

dhinkle@tpgi.com.au




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Directory Prompt
  1996-04-25  4:00 Directory Prompt dhinkle
@ 1996-05-04  4:00 ` Martin Hannigan
  1996-05-06  4:00   ` Timothy M. Wieman
                     ` (3 more replies)
  1996-05-09  4:00 ` Ken Brown
  1 sibling, 4 replies; 13+ messages in thread
From: Martin Hannigan @ 1996-05-04  4:00 UTC (permalink / raw)



In article <4lt1oa$294@random.tpgi.com.au>,
dhinkle <dhinkle@tpgi.com.au> wrote:
>Does anyone know how to make the c shell display the current directory
>in the prompt, and change the prompt as you change directories.
>
>Digital Unix 3.2
>
>dhinkle@tpgi.com.au

I think you have to use 'bash' to be able to accomplish that.

-- 
--
Martin Hannigan (hannigan@shore.net)
PGP Fingerprint: F9 CF 9C 9F E4 CD E0 D5  
	         50 86 93 CA 0C EB 8F 10 



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Directory Prompt
  1996-05-04  4:00 ` Martin Hannigan
@ 1996-05-06  4:00   ` Timothy M. Wieman
       [not found]     ` <4mnec0$r34@gli <4mt0vt$4cu@csugrad.cs.vt.edu>
  1996-05-06  4:00   ` Thomas Leitner
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Timothy M. Wieman @ 1996-05-06  4:00 UTC (permalink / raw)



Martin Hannigan (hannigan@shore.net) wrote:
> In article <4lt1oa$294@random.tpgi.com.au>,
> dhinkle <dhinkle@tpgi.com.au> wrote:
> >Does anyone know how to make the c shell display the current directory
> >in the prompt, and change the prompt as you change directories.
> >
> >Digital Unix 3.2
> >
> >dhinkle@tpgi.com.au

> I think you have to use 'bash' to be able to accomplish that.

Sorry I don't know about csh, but you don't have to have 'bash';
ksh, tcsh, and I'm sure others support it.
Tim
-- 
------------------------------------------------------------------------
Timothy M. Wieman  |  PACE Health Management Systems
Software Engineer  |  1025 Ashworth Rd. Suite 200    Voice: 515.222.1717
  timw@hces.com    |  West Des Moines, IA  50265     Fax:   515.222.1716



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Directory Prompt
  1996-05-04  4:00 ` Martin Hannigan
  1996-05-06  4:00   ` Timothy M. Wieman
@ 1996-05-06  4:00   ` Thomas Leitner
  1996-05-07  4:00   ` Torsten Robert Kirschner
  1996-05-14  4:00   ` David A. Lyons
  3 siblings, 0 replies; 13+ messages in thread
From: Thomas Leitner @ 1996-05-06  4:00 UTC (permalink / raw)



Martin Hannigan (hannigan@shore.net) wrote:
> In article <4lt1oa$294@random.tpgi.com.au>,
> dhinkle <dhinkle@tpgi.com.au> wrote:
> >Does anyone know how to make the c shell display the current directory
> >in the prompt, and change the prompt as you change directories.
> >
> >Digital Unix 3.2
> >
> >dhinkle@tpgi.com.au
> 
> I think you have to use 'bash' to be able to accomplish that.

No. I got the following in my .cshrc file:

    set promptu=`hostname|cut -d'.' -f1`"("\!")"
    alias cd cd \!\* \;set prompt=\"\${promptu}\`echo \$cwd \| \
          sed \'s\?${home}\?\~\?\' \`\>\ \"

Tom

-- 
Tom Leitner, tom@finwds01.tu-graz.ac.at              |\      _,,,---,,_
Dept. of Communications                         zzz. /,`.-'`'    -.  ;-;;,_.
Graz University of Technology                       |,4-  ) )-,_. ,\ (  `'-'
Inffeldgasse 12                                    '---''(_/--'  `-'\_)
A-8010 Graz / Austria / Europe, Phone: +43-316-873-7455, Fax: +43-316-463-697
WWW home page: http://wiis.tu-graz.ac.at/people/tom.html



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Directory Prompt
  1996-05-04  4:00 ` Martin Hannigan
  1996-05-06  4:00   ` Timothy M. Wieman
  1996-05-06  4:00   ` Thomas Leitner
@ 1996-05-07  4:00   ` Torsten Robert Kirschner
  1996-05-07  4:00     ` Dan Pop
  1996-05-14  4:00   ` David A. Lyons
  3 siblings, 1 reply; 13+ messages in thread
From: Torsten Robert Kirschner @ 1996-05-07  4:00 UTC (permalink / raw)



>>>>> "TMW" == Timothy M Wieman <timw@isac.hces.com> writes:
In article <1996May6.165118.16175@isac.hces.com> timw@isac.hces.com (Timothy M. Wieman) writes:
TMW> Martin Hannigan (hannigan@shore.net) wrote:
>> In article <4lt1oa$294@random.tpgi.com.au>,
>> dhinkle <dhinkle@tpgi.com.au> wrote:
>> >Does anyone know how to make the c shell display the current directory
>> >in the prompt, and change the prompt as you change directories.

>> I think you have to use 'bash' to be able to accomplish that.

TMW> Sorry I don't know about csh, but you don't have to have 'bash';
TMW> ksh, tcsh, and I'm sure others support it.

Tim is right. Just put this in your ~/.cshrc file:

set myhost=`expr $HOST : '\([^.]*\).*'`
alias setprompt 'set prompt="$myhost `dirs` > "'
alias cd 'chdir \!* && setprompt'
setprompt

Should work for all csh-like shells. (I'm using tcsh.)
	c u
		T.

--
Torsten Robert Kirschner                            torstenk@ifi.uio.no
torki@mpipf-muenchen.mpg.de  http://www.ifi.uio.no/~torstenk/index.html



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Directory Prompt
  1996-05-07  4:00   ` Torsten Robert Kirschner
@ 1996-05-07  4:00     ` Dan Pop
  1996-05-07  4:00       ` Kevin MacNeil
  1996-05-09  4:00       ` Jeff Aitken
  0 siblings, 2 replies; 13+ messages in thread
From: Dan Pop @ 1996-05-07  4:00 UTC (permalink / raw)



In <4mnec0$r34@glitnir.ifi.uio.no> torstenk@ifi.uio.no (Torsten Robert Kirschner) writes:

>>>>>> "TMW" == Timothy M Wieman <timw@isac.hces.com> writes:
>In article <1996May6.165118.16175@isac.hces.com> timw@isac.hces.com (Timothy M. Wieman) writes:
>TMW> Martin Hannigan (hannigan@shore.net) wrote:
>>> In article <4lt1oa$294@random.tpgi.com.au>,
>>> dhinkle <dhinkle@tpgi.com.au> wrote:
>>> >Does anyone know how to make the c shell display the current directory
>>> >in the prompt, and change the prompt as you change directories.
>
>>> I think you have to use 'bash' to be able to accomplish that.
>
>TMW> Sorry I don't know about csh, but you don't have to have 'bash';
>TMW> ksh, tcsh, and I'm sure others support it.
>
>Tim is right. Just put this in your ~/.cshrc file:
>
>set myhost=`expr $HOST : '\([^.]*\).*'`
>alias setprompt 'set prompt="$myhost `dirs` > "'
                                       ^^^^
Why dirs and not pwd?  Do you really want a list of directories in the
prompt?  Or do you never use pushd? (in which case, dirs is better, indeed)

>alias cd 'chdir \!* && setprompt'

How about pushd and popd?

>setprompt
>
>Should work for all csh-like shells. (I'm using tcsh.)

If you use tcsh it makes no sense to bother with aliases.  Simply use
the tcsh %c feature to put the path in your prompt.  It has the 
advantage that you can control how much of the path you put into your
prompt (a full path is usually not necessary and annoyingly long).

Dan
--
Dan Pop
CERN, CN Division
Email: danpop@mail.cern.ch 
Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Directory Prompt
  1996-05-07  4:00     ` Dan Pop
@ 1996-05-07  4:00       ` Kevin MacNeil
  1996-05-09  4:00       ` Jeff Aitken
  1 sibling, 0 replies; 13+ messages in thread
From: Kevin MacNeil @ 1996-05-07  4:00 UTC (permalink / raw)



danpop@mail.cern.ch (Dan Pop) writes:
]torstenk@ifi.uio.no (Torsten Robert Kirschner) writes:
]>alias setprompt 'set prompt="$myhost `dirs` > "'

]Why dirs and not pwd?  Do you really want a list of directories in the
]prompt?  Or do you never use pushd? (in which case, dirs is better, indeed)

The top of the directory stack is always the current directory.  You can
use cut to print everything up to the first space:

   alias cd 'cd \!* && set prompt="`dirs|cut -f1 -d\ ` % "'

A more convoluted method that grabs the first word from an array:

   alias cd 'cd \!* && set noglob; set dir=`dirs`; unset noglob; setprompt' 
   alias setprompt 'set prompt="${dir[1]} % "'

]How about pushd and popd?

   alias pushd 'pushd \!* && cd .'
   alias popd 'popd \!* && cd .'

]If you use tcsh it makes no sense to bother with aliases.  Simply use the
]tcsh %c feature to put the path in your prompt.  It has the advantage that
]you can control how much of the path you put into your prompt (a full path
]is usually not necessary and annoyingly long).

Agreed.  You can also use %~ if you like ~ notation.

-- 
      Kevin MacNeil            \      Memorial University of Newfoundland
kmacneil@morgan.ucs.mun.ca      /            English & Philosophy



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Directory Prompt
  1996-05-07  4:00     ` Dan Pop
  1996-05-07  4:00       ` Kevin MacNeil
@ 1996-05-09  4:00       ` Jeff Aitken
  1 sibling, 0 replies; 13+ messages in thread
From: Jeff Aitken @ 1996-05-09  4:00 UTC (permalink / raw)



Dan Pop (danpop@mail.cern.ch) wrote:

: If you use tcsh it makes no sense to bother with aliases.  Simply use
: the tcsh %c feature to put the path in your prompt.  It has the 
: advantage that you can control how much of the path you put into your
: prompt (a full path is usually not necessary and annoyingly long).


You can get around this with a 2-line prompt, which I prefer.  I use
tcsh, and have the following aliases:

alias setprompt  'set prompt="\n%B%n@%m%b:%/\n%% "'
alias cd         "chdir \!*; setprompt"
alias pu         "pushd \!*; setprompt"
alias po         "popd \!*; setprompt"
setprompt

I administer several machines here, and it's helpful to know just where
I'm logged in (and who I am!) so that I don't do something silly (like
an inadvertant 'rm -r' :-)  The bold really helps in this regard.

You can do the same sort of thing in bash fairly easily.  
-- 
Jeff Aitken
jaitken@vt.edu




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Directory Prompt
  1996-04-25  4:00 Directory Prompt dhinkle
  1996-05-04  4:00 ` Martin Hannigan
@ 1996-05-09  4:00 ` Ken Brown
  1 sibling, 0 replies; 13+ messages in thread
From: Ken Brown @ 1996-05-09  4:00 UTC (permalink / raw)



In article <4lt1oa$294@random.tpgi.com.au>,
dhinkle <dhinkle@tpgi.com.au> wrote:
>Does anyone know how to make the c shell display the current directory
>in the prompt, and change the prompt as you change directories.
>
>Digital Unix 3.2
>
>dhinkle@tpgi.com.au
>

In ~/.cshrc;

	alias cd 'cd \!*;set prompt="! `hostname|cut -d. -f1`:$cwd:t> "

...will make the prompt show;

hostname:current-dir>

This takes effect after the first "cd" command, so you may want to put a
"cd" in ~/.login....
-- 
----------------------------------------------------------------------
Ken Brown / kbrown@trentu.ca / tel: (705)748-1540 / fax: (705)748-1635
----------------------------------------------------------------------



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Directory Prompt
       [not found]     ` <4mnec0$r34@gli <4mt0vt$4cu@csugrad.cs.vt.edu>
@ 1996-05-10  4:00       ` John C. Fowler
  1996-05-10  4:00         ` John P. Speno
  0 siblings, 1 reply; 13+ messages in thread
From: John C. Fowler @ 1996-05-10  4:00 UTC (permalink / raw)



In article <4mt0vt$4cu@csugrad.cs.vt.edu>, Jeff Aitken <jaitken@vt.edu> wrote:
>Dan Pop (danpop@mail.cern.ch) wrote:
>
>You can get around this with a 2-line prompt, which I prefer.  I use
>tcsh, and have the following aliases:
>
>alias setprompt  'set prompt="\n%B%n@%m%b:%/\n%% "'
>alias cd         "chdir \!*; setprompt"
>alias pu         "pushd \!*; setprompt"
>alias po         "popd \!*; setprompt"
>setprompt
>
>You can do the same sort of thing in bash fairly easily.
>--
>Jeff Aitken

Well gosh, in tcsh, there is a predefined alias, precmd, which gets run
every time just before the prompt comes up.  Thus instead of realiasing
cd, popd, and pushd, just do the following:

alias precmd  'set prompt="\n%B%n@%m%b:%/\n%% "'

That will reset the prompt just before every time the prompt comes up.

john...

                  'When peace like a river attendeth my way,
                      when sorrows like sea billows roll;
                  Whatever my lot thou hast taught me to say,
                   "It is Well!  It is Well, with my soul!"'



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Directory Prompt
  1996-05-10  4:00       ` John C. Fowler
@ 1996-05-10  4:00         ` John P. Speno
  1996-05-11  4:00           ` John Hascall
  0 siblings, 1 reply; 13+ messages in thread
From: John P. Speno @ 1996-05-10  4:00 UTC (permalink / raw)



>Well gosh, in tcsh, there is a predefined alias, precmd, which gets run
>every time just before the prompt comes up.  Thus instead of realiasing
>cd, popd, and pushd, just do the following:

>alias precmd  'set prompt="\n%B%n@%m%b:%/\n%% "'

>That will reset the prompt just before every time the prompt comes up.

Why bother aliasing precmd when just:

set prompt="\n%B%n@%m%b:%/\n%% "

works? YMMV.

-- 
John P. Speno, speno@swarthmore.edu, Swarthmore College Computing Center
	     "There is no wisdom greater than kindness."




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Directory Prompt
  1996-05-10  4:00         ` John P. Speno
@ 1996-05-11  4:00           ` John Hascall
  0 siblings, 0 replies; 13+ messages in thread
From: John Hascall @ 1996-05-11  4:00 UTC (permalink / raw)



John P. Speno <speno@swarthmore.edu> wrote:
}>Well gosh, in tcsh, there is a predefined alias, precmd, which gets run
}>every time just before the prompt comes up.  Thus instead of realiasing
}>cd, popd, and pushd, just do the following:
}>alias precmd  'set prompt="\n%B%n@%m%b:%/\n%% "'
}>That will reset the prompt just before every time the prompt comes up.
}Why bother aliasing precmd when just:
}set prompt="\n%B%n@%m%b:%/\n%% "
}works? YMMV.

   I, for one, hate a big stupid prompt, so I use the tcsh 'cwdcmd'
   alias (much better choice than 'precmd'):

      alias cwdcmd 'title "%#%c04 (%n@%m)"'

   and my title program (see below) to put all that crud in the
   xterm title (added benefit, it's in the icon title too).

John
------------------------------ title.c ---------------------------------------
/*
 * title: put stuff in xterm title using tcsh'ish escapes
 *      : typically used as tcsh's `cwdcmd'
 *	- John Hascall, ISU Comp Ctr
 *      Freely distributable as long as ISU and I am credited.
 *
 * Note: may need local frobbing in function itshome()
 */
#include <time.h>

#define	FALSE	0
#define	TRUE	1

static void	add_cdir();
static void	add_host();
static void	add_line();
static void	add_time();
static void	add_user();
static int	itshome();
static char *	itoa();
static int	match();
static int	levels();
static char *	lastnofm();

extern char *	getenv();
extern int	getuid();
extern int	isatty();
extern char *	ttyname();
extern int	write();

int main(argc, argv)
	int	argc;
	char **	argv;
{
	char	buffer[8192];
	char *	p	= buffer;
	char *	q;
	int	a	= 0;
	int	c;
	int	n;
	int	z;

	/*
	 * if stdout is not a tty quit so we don't send junk down a pipe like:
	 *   (cd /src; tar cf - .) | tar xpf -
	 */
	if (!isatty(0)) return(0);

	/*
	 * first, the special xterm escape sequence initiator
	 */
	*p++ = '\033'; *p++ = ']'; *p++ = '0'; *p++ = ';';

	/*
	 * now get either their format string or the default
	 */
	if (argc == 1) argv[argc++] = "%#%~ (%n@%m)";
	while (++a < argc) {
		q = argv[a];

		/*
		 * process the format string...
		 */
		while (*q != '\0') {
			if ((c = *q++) != '%') {
				*p++ = c;
				continue;
			}
			switch (c = *q++) {
			    case '%':			/* %% inserts % */
				*p++ = '%';
				break;
			    case '#':			/* root indicator */
				if (getuid() == 0) {	/* note difference */
					*p++ = '#';	/* from tcsh def'n */
					*p++ = ' ';
				}
				break;
			    case 'l':
				add_line(c, &p);
				break;
			    case 'n':
				add_user(c, &p);
				break;
			    case 'M':
			    case 'm':
				add_host(c, &p);
				break;
			    case '/':
			    case '~':
				add_cdir(c, &p, (c == '~'), FALSE, FALSE, 0);
				break;
			    case 'c':
			    case '.':
			    case 'C':
				z = FALSE;
				n = 1;
				if (*q == '0') { ++q; z = TRUE; }
				if ((*q >= '1') && (*q <= '9')) n = *q++ - '0';
				add_cdir(c, &p, (c != 'C'), TRUE, z, n);
				break;
			    case 't': case '@': case 'T': case 'd': case 'D':
			    case 'w': case 'W': case 'y': case 'Y':
				add_time(c, &p);
				break;
			    default:	/* %X, if X unknown, then nothing */
				break;
			}
		}
		*p++ = ' ';
	}
	
	/*
	 * a hex 0x07 terminates the escape sequence (put it over last space)
	 */
	p[-1] = '\007';

	/*
	 * splat it out
	 */
	(void)write(1, buffer, p - buffer);
	return (0);
}

/*
 * get current dir with much twiddling and such...
 */
static void add_cdir(c, pp, subs, abbrev, before, n)
	int	c;
	char **	pp;
	int	subs;
	int	abbrev;
	int	before;
	int	n;
{
	char *	p	= *pp;
	char *	pwd;
	char *	w;
	char *	u;
	char *	ldr;
	int	m;
	int	tilde	= FALSE;

	if ((pwd = getenv("PWD")) == NULL) pwd = "(Where?)";

	/*
	 * do ~[user] substitution if requested
	 */
	if (subs) {
		if ((m = itshome(pwd)) != 0) {		/* it's a home */
			pwd += m;
			if ((u = getenv("USER")) == NULL) u = "";
			for (w = pwd; *u != '\0'; ++w,++u) {
				if (*u != *w) break;
			}
			if (*u == '\0') pwd = w;	/* it's our home */
			tilde = TRUE;
		}
	}

	/*
	 * do they only want a trailing few components?
	 */
	if (abbrev) {
		ldr = pwd;
		m = levels(pwd);
		pwd = lastnofm(pwd, n, m);
		/*
		 * if we actually trimmed the pwd...
		 */
		if (pwd != ldr) {
			/*
			 * if they want a count of trimmed levels...
			 */
			if (before)  {
				/*
				 * leader (upto+including first /) comes first
				 */
				if (tilde) *p++ = '~';		/* add tilde */
				while (*ldr != '\0') {
					if ((*p++ = *ldr++) == '/') break;
				}
				*p++ = '<';
				w = itoa(m - n);
				while (*w != '\0') *p++ = *w++;
				*p++ = '>';
			}
			tilde = FALSE;		/* would be spurious now */
		}
	}
	if (tilde) *p++ = '~';			/* add the tilde if needed */

	/*
	 * and the rest...
	 */
	while (*pwd != '\0') *p++ = *pwd++;
	*pp = p;
}

/*
 * FQDN or short hostname
 */
static void add_host(c, pp)
	int	c;
	char **	pp;
{
	char *	p	= *pp;
	char	host[64] = "(Which?)";
	char *	hst	= host;
	char *	h;

	(void)gethostname(host, sizeof(host));
	if (c == 'm') {
		for (h = hst; *h != '\0'; ++h) {
			if (*h == '.') {
				*h = '\0';
				break;
			}
		}
	}
	while (*hst != '\0') *p++ = *hst++;
	*pp = p;
}

/*
 * ttyline (less /dev/ prefix)
 */
static void add_line(c, pp)
	int	c;
	char **	pp;
{
	char *	p	= *pp;
	char *	t;
	int	m;

	if ((t = ttyname(1)) == NULL) t = "(How?)";
	if ((m = match(t, "/dev/")) != 0) t += m;
	while (*t != '\0') *p++ = *t++;
	*pp = p;
}

/*
 * various time/date bits
 */
static void add_time(c, pp)
	int	c;
	char **	pp;
{
	char *			p	= *pp;
	char *			t;
	int			hr;
	static time_t		now	= 0;
	static struct tm	tm;
	static char *		day[]	= {"Sun", "Mon", "Tue",
					   "Wed", "Thu", "Fri", "Sat"};
	static char *		mon[]	= {"Jan", "Feb", "Mar", "Apr",
					   "May", "Jun", "Jul", "Aug",
					   "Sep", "Oct", "Nov", "Dec"};

	if (now == 0) {
		now = time(NULL);
		tm = (*localtime(&now));
	}
	switch (c) {
	    case 't':
	    case '@':
		hr = tm.tm_hour;
		if (hr >= 12) hr -= 12;
		t = itoa(hr);
		while (*t != '\0') *p++ = *t++;
		*p++ = ':';
		t = itoa(tm.tm_min);
		while (*t != '\0') *p++ = *t++;
		t = (hr == tm.tm_hour) ? "am" : "pm";
		break;
	    case 'T':
		t = itoa(tm.tm_hour);
		while (*t != '\0') *p++ = *t++;
		*p++ = ':';
		t = itoa(tm.tm_min);
		break;
	    case 'd':
		t = day[tm.tm_wday];
		break;
	    case 'D':
		t = itoa(tm.tm_mday);
		break;
	    case 'w':
		t = mon[tm.tm_mon];
		break;
	    case 'W':
		t = itoa(tm.tm_mon + 1);
		break;
	    case 'y':
		t = itoa(tm.tm_year);
		break;
	    case 'Y':
		t = itoa(1900 + tm.tm_year);
		break;
	}
	while (*t != '\0') *p++ = *t++;
	*pp = p;
}

/*
 * username (in case they forget :)
 */
static void add_user(c, pp)
	int	c;
	char **	pp;
{
	char *	p	= *pp;
	char *	u;

	if ((u = getenv("USER")) == NULL) u = "(Who?)";
	while (*u != '\0') *p++ = *u++;
	*pp = p;
}

/* ====================== HELPER FUNCTIONS =========================== */

static int itshome(path)
	char *	path;
{
	int	m;
	int	m0;
	int	m1;

	/*
	 * first, some hopefully reasonably generic tests
	 */
	if ((m = match(path, "/home/")) != 0) return (m);
	if ((m = match(path, "/usr/users/")) != 0) return (m);
	if ((m = match(path, "/usr/people")) != 0) return (m);
#ifdef	ISU
	/*
	 * now, some very local frobbing...
	 */
	if ((m = match(path, "/nfs/*fs-*/u*/")) != 0) return (m);
	if (((m0 = match(path, "/afs/iastate.edu/")) != 0) ||
	    ((m0 = match(path, "/afs/isu/")) != 0)) {
		if ((m1 = match(path + m0, "users/*/*/")) != 0) return (m0+m1);
		if ((m1 = match(path + m0, "group/")) != 0) return (m0+m1);
		if ((m1 = match(path + m0, "public/")) != 0) return (m0+m1);
		if ((m1 = match(path + m0, "private/")) != 0) return (m0+m1);
		if ((m1 = match(path + m0, "rental/")) != 0) return (m0+m1);
		if ((m1 = match(path + m0, "project/")) != 0) return (m0+m1);
		if ((m1 = match(path + m0, "academic/")) != 0) return (m0+m1);
	}
#endif
	return (0);
}

/*
 * a not-very powerfull, but small wildcard matcher
 */
static int match(s, p)
	char *	s;
	char *	p;
{
	char *	q	= s;

	while (*p != '\0') {
		if (*p == '*') {		/* match stuff */
			++p;
			while (*q != *p) {
				if (*q == '\0') return (0);
				++q;
			}
			continue;
		}
		if (*p++ != *q++) return (0);
	}
	return (q - s);
}

/*
 * int-to-ascii (note: static buffer)
 */
static char * itoa(i)
	int	i;
{
	static char	buffer[16];
	char *		a =	buffer + 16;
	*--a = '\0';
	do {
		*--a = '0' + (i % 10);
		i /= 10;
	} while (i != 0);
	return (a);
}

/*
 * how many levels in a path? * (note: doesn't handle a trailing slash!)
 */
static int levels(path)
	char *	path;
{
	int	lvls	= 0;
	char *	p	= path;

	while (*p != '\0') {
		if (*p++ == '/') ++lvls;
	}
	return (lvls);
}

/*
 * point to last n levels of the m levels present in a path
 * lastnofm("/afs/iastate.edu/system/rw/dec/v4/usr", 3, 7) == "dec/v4/usr"
 * lastnofm("/usr/tmp", 2, 2) == "/usr/tmp"
 */
static char * lastnofm(path, n, m)
	char *	path;
	int	n;
	int	m;
{
	if (n >= m) return (path);		/* all of it (or more :) */
	for (m -= n; m >= 0; --m) {
		do {} while (*path++ != '/');
	}
	return (path);
}
---------------------------- title.1 ----------------------------------
.TH title 1 "31 December 1995"
.ds ]W ISU Project Vincent
.\"
.\" First define macros "SB (small&bold)", "TY(typewriter)", & "M(man ref)"
.\"
.de SB
.if !"\\$1"" \\s-1\\fB\&\\$1\\s0\\fR\\$2 \\$3 \\$4 \\$5
..
.\"
.de T
.ft CW
..
.\"
.de TY
.if t .T
.if n ``\c
\\$1\c
.if t .ft P
.if n \&''\c
\\$2
..
.\"
.de M
\\fI\\$1\\fR\\|(\\$2)\\$3
..
.\"
.\" The manual page
.\"
.SH NAME
title \- set the title of an xterm
.SH SYNTAX
.NXR "title command"
.B title
[
.I escapestring
]
.SH DESCRIPTION
The
.PN title
command sets an xterm's title and icon strings using
.I escapestring .
Typically, these strings are displayed by the window manager
(e.g., in the wide bar at the top of border).
The
.I escapestring
is scanned for \fB%\fIc\fR escape sequences.
A subset of the
.PN tcsh
shell's prompt escape sequences is recognized.
.PP
If 
.I escapestring
is omitted a default string of
"\fB%#%~ (%n@%m)\fR"
is used.
.PP
The title command can be invoked directly or, more commonly,
through the
.PN tcsh
shell's special
.I cwdcmd
alias.
.SH ESCAPES
.EX
	\fB%%\fR		A single % character.
	\fB%/\fR		Current working directory.
	\fB%~\fR		Current working directory, does \fB~\fR and \fB~\fIuser\fR substitution.
	\fB%c\fR[\fB0\fR][\fIn\fR]	Trailing [\fIn\fR] component(s) of current working directory.
			Include \fB0\fR for a count of elided components.
			Does ~ and ~\fIuser\fR substitution.
	\fB%.\fR[\fB0\fR][\fIn\fR]	Identical to \fB%c\fR[\fB0\fR][\fIn\fR] above.
	\fB%C\fR[\fB0\fR][\fIn\fR]	As above, no \fB~\fR or \fB~\fIuser\fR substitution.
	\fB%#\fR		If root, "\fB#\fR ", else "".
	\fB%n\fR		The username.
	\fB%M\fR		The full hostname.
	\fB%m\fR		The short hostname.
	\fB%l\fR		The line (tty) the user is logged on.
	\fB%t\fR		Current time of day, in 12-hour, am/pm format.
	\fB%@\fR		Identical to \fB%t\fR above.
	\fB%T\fR		Current time of day, in 24-hour format.
	\fB%d\fR		The weekday in <Day> format.
	\fB%D\fR		The day in dd format.
	\fB%w\fR		The month in <Mon> format.
	\fB%W\fR		The month in mm format.
	\fB%y\fR		The year in yy format.
	\fB%Y\fR		The year in yyyy format.
.EE
.SH EXAMPLES
.EX
	title "this is a title"
	alias cwdcmd 'title "%c04 (%n@%m)"'
	alias telnet 'title \\!:*; /usr/ucb/telnet -ax \\!:*;cd .'
.EX
.SH ENVIRONMENT
.EX
	$PWD		Used for %/ %~ %c %. and %C escapes.
	$USER	Used for %n escape.
.EE
.SH SEE ALSO
.M xterm 1 ,
.M tcsh 1 ,
.M mwm 1
.SH AUTHOR
John Hascall
.I <john@iastate.edu>\c
,
\s-1Project Vincent\s0, ISU Computation Ctr.
.SH COPYRIGHT
Copyright 1995, \s-1Iowa State University\s0.
All rights reserved.
---------------------------------- end -------------------------------------
-- 
John Hascall                ``An ill-chosen word is the fool's messenger.''
Moderator, comp.unix.wizards
Systems Software Engineer, ISU Comp Center + Ames, IA  50011 + 515/294-9551
<a href="http://www.cc.iastate.edu/staff/systems/john/">My Homepage</a>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Directory Prompt
  1996-05-04  4:00 ` Martin Hannigan
                     ` (2 preceding siblings ...)
  1996-05-07  4:00   ` Torsten Robert Kirschner
@ 1996-05-14  4:00   ` David A. Lyons
  3 siblings, 0 replies; 13+ messages in thread
From: David A. Lyons @ 1996-05-14  4:00 UTC (permalink / raw)



Martin Hannigan wrote:
> 
> In article <4lt1oa$294@random.tpgi.com.au>,
> dhinkle <dhinkle@tpgi.com.au> wrote:
> >Does anyone know how to make the c shell display the current 
> >directory in the prompt, and change the prompt as you change 
> >directories.
> >
> >Digital Unix 3.2
> >
> >dhinkle@tpgi.com.au
> 
> I think you have to use 'bash' to be able to accomplish that.
> 

realias the 'cd' builtin, like this (for example):

alias fp 'set prompt="[ ! ] ${USER}@${HOST}:${PWD}% "'
alias cd "cd \!*;fp"
alias pu "pushd \!*;fp"
alias po "popd \!*;fp"

--
David Lyons - Digital UNIX Support m/s ALF1-3/P27 / 1-800-354-9000
x75850
Digital Equipment Corporation
5555 Windward Parkway West
Alpharetta, GA 30201-7407      
lyonsd@alf.dec.com

"[Bill Clinton] has kept the promises he meant to keep."
     --GEORGE STEPHANOPOLOUS, CNN'S "LARRY KING LIVE," 
       2/15/96



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~1996-05-14  4:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-04-25  4:00 Directory Prompt dhinkle
1996-05-04  4:00 ` Martin Hannigan
1996-05-06  4:00   ` Timothy M. Wieman
     [not found]     ` <4mnec0$r34@gli <4mt0vt$4cu@csugrad.cs.vt.edu>
1996-05-10  4:00       ` John C. Fowler
1996-05-10  4:00         ` John P. Speno
1996-05-11  4:00           ` John Hascall
1996-05-06  4:00   ` Thomas Leitner
1996-05-07  4:00   ` Torsten Robert Kirschner
1996-05-07  4:00     ` Dan Pop
1996-05-07  4:00       ` Kevin MacNeil
1996-05-09  4:00       ` Jeff Aitken
1996-05-14  4:00   ` David A. Lyons
1996-05-09  4:00 ` Ken Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox