Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Tutorials & Tips
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Tutorials & Tips
The place to find Ubuntu related Tips & Tricks.

 
Thread Tools Display Modes
Old January 21st, 2008   #1
PurposeOfReason
100% Pure Ubuntu
 
PurposeOfReason's Avatar
 
Join Date: May 2007
Location: Washington
Beans: 914
Send a message via AIM to PurposeOfReason
HOWTO: Customize terminal header

By default, the terminal header is a bit boring and unattractive. This format is determined by your ~/.bashrc file. By default there will be many lines, most of which don't matter. We want the PS1 line (which determines what to show) looks like the following:
Code:
PS1='[\u@\h \W]\$ '
The PS1 line will show anything between the opening and closing ' , including spaces. You have many option of what to put, all listed here:
Code:
\a     an ASCII bell character (07)
            \d     the date in "Weekday Month Date" format (e.g., "Tue May 26")
            \D{format}
                   the format is passed to strftime(3) and the result is inserted into the  prompt  string;  an  empty  format
                   results in a locale-specific time representation.  The braces are required
            \e     an ASCII escape character (033)
            \h     the hostname up to the first `.'
            \H     the hostname
            \j     the number of jobs currently managed by the shell
            \l     the basename of the shell's terminal device name
            \n     newline
            \r     carriage return
            \s     the name of the shell, the basename of $0 (the portion following the final slash)
            \t     the current time in 24-hour HH:MM:SS format
            \T     the current time in 12-hour HH:MM:SS format
            \@     the current time in 12-hour am/pm format
            \A     the current time in 24-hour HH:MM format
            \u     the username of the current user
            \v     the version of bash (e.g., 2.00)
            \V     the release of bash, version + patch level (e.g., 2.00.0)
            \w     the current working directory, with $HOME abbreviated with a tilde
            \W     the basename of the current working directory, with $HOME abbreviated with a tilde
            \!     the history number of this command
            \#     the command number of this command
            \$     if the effective UID is 0, a #, otherwise a $
            \nnn   the character corresponding to the octal number nnn
            \\     a backslash
            \[     begin  a sequence of non-printing characters, which could be used to embed a terminal control sequence into
                   the prompt
            \]     end a sequence of non-printing characters
You may put them in any order that you wish, as long as that they are within you're ' s. You may also use colors if you so wish, a full list of colors is below:
Code:
Black       0;30     Dark Gray     1;30
Blue        0;34     Light Blue    1;34
Green       0;32     Light Green   1;32
Cyan        0;36     Light Cyan    1;36
Red         0;31     Light Red     1;31
Purple      0;35     Light Purple  1;35
Brown       0;33     Yellow        1;33
Light Gray  0;37     White         1;37
My PS1 line looks as follows:
Code:
PS1='\[\e[0;34m\][\W]\[\e[m\] '
which, based on the above tables means to use blue to show the current directory, and then switch pack to the default color ([\e[m\] for the rest of the output. There are no limits to how short or long you make this line, a good example line is as follows:
Code:
PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$ \[\e[m\]\[\e[1;37m\] '
Of course these aren't the only functions of the ~/.bashrc file, but as far as the header goes, those are your options to what will show.



**If any of this makes no sense, please let me know and I'll try to expand it.
PurposeOfReason is offline   Reply With Quote
Old January 24th, 2008   #2
m.musashi
Dark Roasted Ubuntu
 
m.musashi's Avatar
 
Join Date: Jan 2006
Location: Edge of Time
My beans are hidden!
Ubuntu 9.04 Jaunty Jackalope
Re: HOWTO: Customize terminal header

Quote:
Originally Posted by PurposeOfReason View Post
By default, the terminal header is a bit boring and unattractive. This format is determined by your ~/.bashrc file. By default there will be many lines, most of which don't matter. We want the PS1 line (which determines what to show) looks like the following:
Code:
PS1='[\u@\h \W]\$ '
Very cool. But I don't see a section like that. I'm guessing it's in this mess
Code:
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color)
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    ;;
*)
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    ;;
esac

# Comment in the above and uncomment this below for a color prompt
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
    ;;
*)
    ;;
esac
But I don't know where to start commenting and what to change. Any pointers?

Thanks.
__________________
Join Team Ubuntu and fold@home.
The most excellent Colorado Ubuntu Local Team
m.musashi is offline   Reply With Quote
Old January 24th, 2008   #3
PurposeOfReason
100% Pure Ubuntu
 
PurposeOfReason's Avatar
 
Join Date: May 2007
Location: Washington
Beans: 914
Send a message via AIM to PurposeOfReason
Re: HOWTO: Customize terminal header

Remember you posted this here so you can revert it if I'm wrong. However, notice the two PS1 lines at the beginning? They are essentially the same thing, one is just in color. So I'm just going to comment them out, then put your own PS1 line somewhere, preferably at the beginning, and see if that works.

Code:
# set a fancy prompt (non-color, unless we know we "want" color)
#case "$TERM" in
#xterm-color)
#   PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
#    ;;
#*)
#    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
#    ;;
#esac

# Comment in the above and uncomment this below for a color prompt
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
    ;;
*)
    ;;
esac
PurposeOfReason is offline   Reply With Quote
Old January 24th, 2008   #4
patrock
First Cup of Ubuntu
 
Join Date: Jan 2008
Beans: 3
Re: HOWTO: Customize terminal header

Just append it to the bottom of the file. It will just override any previously set ones.

Here's mine:
Code:
PS1='\n[\[\e[36;40m\]\u\[\e[0m\]] \[\e[32;40m\]\W \[\e[0m\]\$ '
patrock is offline   Reply With Quote
Old January 24th, 2008   #5
m.musashi
Dark Roasted Ubuntu
 
m.musashi's Avatar
 
Join Date: Jan 2006
Location: Edge of Time
My beans are hidden!
Ubuntu 9.04 Jaunty Jackalope
Re: HOWTO: Customize terminal header

@PurposeOfReason: Hey, that worked. Thanks. I thought maybe the bit about ${USER}@${HOSTNAME} had to change as that's what I normally have as part of the prompt. Guess not. That's one confusing file though.
__________________
Join Team Ubuntu and fold@home.
The most excellent Colorado Ubuntu Local Team

Last edited by m.musashi; January 24th, 2008 at 10:43 PM.. Reason: clarify
m.musashi is offline   Reply With Quote
Old January 28th, 2008   #6
D-EJ915
A Carafe of Ubuntu
 
D-EJ915's Avatar
 
Join Date: Sep 2007
Location: Virginia Beach, VA
Beans: 93
Ubuntu 7.04 Feisty Fawn
Send a message via AIM to D-EJ915 Send a message via MSN to D-EJ915
Re: HOWTO: Customize terminal header

If you want to try it out first to see what it does, simply type "export " then your PS1=... part so it would look like

Quote:
export PS1='\n[\[\e[36;40m\]\u\[\e[0m\]] \[\e[32;40m\]\W \[\e[0m\]\$ '
for the one patrock posted.

This doesn't do anything to any files, it just changes it for that one window.
D-EJ915 is offline   Reply With Quote
Old February 16th, 2008   #7
kaiju
Gee! These Aren't Roasted!
 
kaiju's Avatar
 
Join Date: Aug 2007
Location: Cluj/Kolozsvár, Romania
Beans: 189
Re: HOWTO: Customize terminal header

hey, this is a very fine little thread.

how about making a collection of terminal headers people are using?
kaiju is offline   Reply With Quote
Old March 3rd, 2008   #8
thyultimate
First Cup of Ubuntu
 
Join Date: Jul 2007
Location: India
Beans: 6
Hardy Heron (Ubuntu Development)
Send a message via Yahoo to thyultimate Send a message via Skype™ to thyultimate
Re: HOWTO: Customize terminal header

wow!! i didn't even know that something like ~/.bashrc existed, thanks a lot guys

Last edited by thyultimate; March 3rd, 2008 at 03:13 PM.. Reason: oops sorry wrong thread, cant i delete this post??
thyultimate is offline   Reply With Quote
Old March 12th, 2008   #9
Lostincyberspace
Ubuntu Extra Shot
 
Lostincyberspace's Avatar
 
Join Date: Aug 2007
Location: Torrington, Wyoming
Beans: 376
Ubuntu 8.10 Intrepid Ibex
Send a message via AIM to Lostincyberspace Send a message via MSN to Lostincyberspace Send a message via Yahoo to Lostincyberspace
Re: HOWTO: Customize terminal header

Hey I have a question I was playing with my colors and I got a color I really like but cant get it again.
Could some one tell what to put in to get the color
I have include a picture of it.
Attached Images
File Type: png Screenshot-Terminal.png (84.1 KB, 783 views)
__________________
Quote:
すべてと、そして、すべてへのリナックスは自由を鳴らせました。
Linux to all, and to all, let freedom ring.
Lostincyberspace is offline   Reply With Quote
Old March 12th, 2008   #10
PurposeOfReason
100% Pure Ubuntu
 
PurposeOfReason's Avatar
 
Join Date: May 2007
Location: Washington
Beans: 914
Send a message via AIM to PurposeOfReason
Re: HOWTO: Customize terminal header

Quote:
Originally Posted by Lostincyberspace View Post
Hey I have a question I was playing with my colors and I got a color I really like but cant get it again.
Could some one tell what to put in to get the color
I have include a picture of it.
That is either 1;31 or 0;31.
PurposeOfReason is offline   Reply With Quote

Bookmarks

Tags
header, terminal

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:09 AM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry