From owner-freebsd-questions Thu Aug 13 08:25:45 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id IAA11901 for freebsd-questions-outgoing; Thu, 13 Aug 1998 08:25:45 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from emu.sourcee.com (emu.sourcee.com [199.201.159.173]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA11871 for ; Thu, 13 Aug 1998 08:25:38 -0700 (PDT) (envelope-from nrice@emu.sourcee.com) Received: (from nrice@localhost) by emu.sourcee.com (8.8.8/8.8.3) id LAA08682; Thu, 13 Aug 1998 11:22:27 -0400 (EDT) Message-ID: <19980813112226.A8609@emu.sourcee.com> Date: Thu, 13 Aug 1998 11:22:26 -0400 From: Norman C Rice To: Sue Blake , Peihan Wang Cc: freebsd-questions@FreeBSD.ORG, jgrosch@mooseriver.com, mhenry@white.ug.cs.usyd.edu.au Subject: Re: Re: PS1 (command line prompt) in .profile References: <19980813183425.65187@welearn.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.91.1i In-Reply-To: <19980813183425.65187@welearn.com.au>; from Sue Blake on Thu, Aug 13, 1998 at 06:34:25PM +1000 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 , > > > > // 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 > > #include > > #include > > > > 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