Date: Tue, 4 Aug 1998 03:50:26 +0200 (MET DST) From: Sascha Schumann <sas@schell.de> To: Studded <Studded@dal.net> Cc: William Woods <wwoods@cybcon.com>, "freebsd-questions@FreeBSD.ORG" <freebsd-questions@FreeBSD.ORG> Subject: Re: BASH prompt question Message-ID: <Pine.LNX.3.96.980804031907.17819A-100000@www.schell.de> In-Reply-To: <35C657D9.4B2577D4@dal.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 3 Aug 1998, Studded wrote:
> Sascha Schumann wrote:
> >
> > On Sun, 2 Aug 1998, William Woods wrote:
> >
> > > I would like to make my bash prompt show a little more info, like what dir the
> > > user is in. How would I do this?
> >
> > Edit /etc/profile and insert at the end:
> >
> > test "$SHELL" = "/bin/bash" && test -e ~/.bashrc && source ~/.bashrc
>
> Why are you inserting a test to accomplish something that bash does by
> default?
Because it's not default nor done automatically.
I don't like to quote documents everybody has. But if people are too lazy
to look at it, I have to do it...
------------------------------------
INVOCATION
A login shell is one whose first character of argument
zero is a -, or one started with the --login option.
An interactive shell is one whose standard input and out
put are both connected to terminals (as determined by
isatty(3)), or one started with the -i option. PS1 is set
and $- includes i if bash is interactive, allowing a shell
script or a startup file to test this state.
...
When bash is invoked as an interactive login shell, it
first reads and executes commands from the file /etc/pro
file, if that file exists. After reading that file, it
looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the
first one that exists and is readable. The --noprofile
option may be used when the shell is started to inhibit
this behavior.
...
When an interactive shell that is not a login shell is
started, bash reads and executes commands from ~/.bashrc,
if that file exists. This may be inhibited by using the
--norc option. The --rcfile file option will force bash
to read and execute commands from file instead of
~/.bashrc.
...
------------------------
To end this ``discussion'':
~/.bashrc _will be_ sourced automatically by bash, if you...
o do a `su [username]'
o start a xterm
It will _not_be automatically sourced, if you...
o do a `su - [username]'
o login from console
o use sth else to login remotely
> > PS1='\u@\h:`pwd -P` $ '
> > export PS1
>
> Again, working too hard. :) Why call a shell function every time you
> hit return? The following accomplishes what you have there, and adds
> your correction for the \$:
My profile files etc are set up in the way
A=asdasd
B=sthelse
C=hohoh
export A B C
So, I don't have to type 1000s of exports...
We probably don't need to discuss the overhead of either method ;)
> export PS1='\u@\h: \w \$'
>
> This syntax is available in bash 2 and above, but you should be using
> bash 2 anyway. :)
Because I've used older versions which didn't have it. The last thing I do
is to look for more features for my prompt ;)
<snip>
> Here's some info from misc.c in xterm's source about the escape codes
> for the title and icon:
>
> case 0: /* new icon name and title*/
> case 1: /* new icon name only */
> case 2: /* new title only */
>
> This may be more details than the original poster wanted, but the goal
> is to show what's possible. Some people have implemented colored prompts
> using ansi escape codes, but I haven't gotten that obsessed yet. :)
A red prompt would be nice, if you are root. That makes you even think a
little bit more before doing sth like "/tmp # rm -R wfiles /" instead of
"/tmp # cp -R wfiles /" like I did some days ago :-(( ;)
Greetings,
Sascha
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?Pine.LNX.3.96.980804031907.17819A-100000>
