[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ???current directory in prompt in bash???



At 08:38 AM 12/8/1998 +0000, Rich Hartman wrote:
>Is there a way to have bash include the current directory in the 
>prompt of bash? Actually, let me re-phrase that.... my "root" account 
>DOES include the current directory in the the prompt, but I have no 
>idea why or how... I've tried to copy my root's .bash_profile to my 
>"regular-user's" .bash_profile, but it still doesn't work.... any 
>ideas?
>
>Thanks in advance....
>
>Rich

Yes. In your .bash_profile file, include a couple of lines like:
PS1='\h:s[\u] $PWD \$ '
export PS1

This sets the "prompt" so that it displays the computer's hostname (\h),
the shell you're using (\s), the name of the logged-in user (\u), and the
current working directory ($PWD) followed by a $ prompt. Some of the more
knowledgeable people might make suggestions for making this more
bullet-proof; I think the system may get confused as to the length of the
prompt which might cause wrapping problems etc unless other codes are
thrown in, etc. However, this prompt works for me.

You can experiment simply by typing at the prompt something like:
export PS1="$PWD"
and etc, then add the desired line to .bash_profile for future logins.

You can also take a look at man console_codes (or search in
www.linuxgazette.com for 2-cent tips concerning adding color to your
prompt) if you want to do such things as adding color to your prompt.

For example, on another machine I've got a prompt that looks like:
PS1="\[\n\t\]\n^[[44;01;33m\h[\u]:\$PWD^[[m\] "
which gives me the current time followed by a newline followed by the same
prompt mentioned above with yellow letters on a blue background. The ^[ is
a special escape sequence; I'm sorry, I don't remember how to enter that
sequence, maybe Ctrl-[ does it. At any rate, not all editors will let you
enter that sequence, but I did mine in vi.


Reply to: