Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Aug 1998 11:22:26 -0400
From:      Norman C Rice <nrice@emu.sourcee.com>
To:        Sue Blake <sue@welearn.com.au>, Peihan Wang <peihanw@mx.cei.gov.cn>
Cc:        freebsd-questions@FreeBSD.ORG, jgrosch@mooseriver.com, mhenry@white.ug.cs.usyd.edu.au
Subject:   Re: Re: PS1 (command line prompt) in .profile
Message-ID:  <19980813112226.A8609@emu.sourcee.com>
In-Reply-To: <19980813183425.65187@welearn.com.au>; from Sue Blake on Thu, Aug 13, 1998 at 06:34:25PM %2B1000
References:  <Pine.BSF.3.96.980813152436.462A-100000@wph.bbs.edu.cn> <19980813183425.65187@welearn.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Aug 13, 1998 at 06:34:25PM +1000, Sue Blake wrote:
> [moved to freebsd-questions where it should have started]
> 
> On Thu, Aug 13, 1998 at 03:44:46PM +0800, Peihan Wang wrote:
> > >> 
> > >> Hello , gurus !
> > >> 
> > >> I am using bash (version: 2.01) on my 2.2.6 box.
> > >> I put the following line in my .profile:
> > >> 
> > >> PS1='`pwd`$ '
> > >> 
> > >> It works well in console mode, But after I start X
> > >> it does not take any effect in xterm. By the way,
> > >> I am using lesstif as my window manager. I do not
> > >> know what to do :-(
> > >>
> > --------------------------- Josef's Answer --------------------
> > >
> > >Read your man page. Bash uses 2 init file, .bashrc and .bash_profile.
> > >.bash_profile gets run when you first login. .bashrc get run for each
> > >term that your account/process create. So in your .bash_profile you
> > >would have the line 
> > >
> > >    export PS1='`pwd`$ '
> > >
> > >That should do it
> > >
> > --------------------------  Henry's Answer --------------------
> > >
> > >You need to give the -ls argument to xterm:
> > >
> > >xterm -ls
> > >
> > >This indicates that the shell in the xterm is a login shell,
> > >and thus it will read your .profile.
> > >
> > ################################################################
> > 
> > Thank you very much !
> > 
> > I write the following trinket as a gift to all FreeBSD users.
> > It is very primitive and everyone can modify it for his/her
> > own purpose.
> > 
> > 
> > // file name   : my-path-prompt.cc
> > // last update : Aug/13/1998
> > // author      : Peihan Wang <peihanw@usa.net> , <peihanw@mx.cei.gov.cn>
> > 
> > // This program is derived from pwd.
> > // Sometimes when you set PS1='`pwd`$ ' in your .profile or .bashrc,
> > // it is very annoying that while you were doing something
> > // in a relatively deep directory the PATH prompt is so long
> > // that cause your eyes dizzy.
> > 
> > // So, compile this program and put it in ~/bin/ and modify your
> > // profile. (PS1='`my-path-prompt`$ ')
> > 
> > // You can modify the two consts as you wish
> > // or you can add command line args to make it flexible.
> > 
> > #include <iostream.h>
> > #include <unistd.h>
> > #include <string.h>
> > 
> > const int PROMPT_MAX_LENTH = 25;
> > const char * ADD_ON_STRING = "..|";
> > 
> > main ()
> > {
> >  char * current_path = NULL;
> >  char * p = NULL;
> > 
> >  if ((p = getcwd(NULL, 0)) == NULL) {
> >    cerr << "getcwd() error\n";
> >    exit(-1);
> >  }
> > 
> >  int path_lenth = strlen(p);
> >  int add_on_lenth = strlen(ADD_ON_STRING);
> >  char * trimed_path = NULL;
> > 
> >  current_path = new char [path_lenth + 1];
> >  strcpy(current_path, p);
> >  if (path_lenth <= PROMPT_MAX_LENTH) {
> >    cout << current_path;
> >  }
> >  else {
> >    trimed_path = new char [PROMPT_MAX_LENTH + 1];
> >    strcpy(trimed_path, ADD_ON_STRING);
> >    char * pp = current_path;
> >    for (int i = 0;
> > 	i < (path_lenth - PROMPT_MAX_LENTH + add_on_lenth);
> > 	i++) {
> >      pp ++;
> >    }
> >    strcat(trimed_path, pp);
> >    cout << trimed_path;
> >    delete trimed_path;
> >  }
> >  delete current_path;
> >  return 0;
> > }
> > 
> 
> 
> I don't speak C, and I don't understand why I would want a program to
> do what .bashrc does. Is this better?

It appears to be a C++ program and its benefit is to keep the prompt
length limited to a reasonable size. Some programs, e.g. ncftp, provide
a similar interface by replacing the missing path components with
ellipses.

If there is no requirement for prompt length truncation, the
following statement in the users ~/.bash_profile (initial login) 
and ~/.bashrc (sub shells) should work fine.

  PS1='\w\$ '

If multiple hosts are involved try

  PS1='\h:\w\$ '

which sets the prompt to ``hostname:path$ ''
-- 
Regards,
Norman C. Rice, Jr.

> -- 
> 
> Regards,
>         -*Sue*-

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980813112226.A8609>