Page 1 of 3 123 LastLast
Results 1 to 10 of 30

Thread: HOWTO: Customize terminal header

  1. #1
    Join Date
    May 2007
    Location
    Washington
    Beans
    911

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Edge of Time
    Beans
    Hidden!
    Distro
    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.

  3. #3
    Join Date
    May 2007
    Location
    Washington
    Beans
    911

    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

  4. #4
    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\]\$ '

  5. #5
    Join Date
    Jan 2006
    Location
    Edge of Time
    Beans
    Hidden!
    Distro
    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.
    Last edited by m.musashi; January 25th, 2008 at 03:43 AM. Reason: clarify

  6. #6
    Join Date
    Sep 2007
    Location
    Virginia Beach, VA
    Beans
    93
    Distro
    Kubuntu 9.04 Jaunty Jackalope

    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

    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.

  7. #7
    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?

  8. #8
    Join Date
    Jul 2007
    Location
    India
    Beans
    6
    Distro
    Hardy Heron (Ubuntu Development)

    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 08:13 PM. Reason: oops sorry wrong thread, cant i delete this post??

  9. #9
    Join Date
    Aug 2007
    Location
    Torrington, Wyoming
    Beans
    372
    Distro
    Ubuntu 8.10 Intrepid Ibex

    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 Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Screenshot-Terminal.png 
Views:	1253 
Size:	84.1 KB 
ID:	62406  
    すべてと、そして、すべてへのリナックスは自由を鳴らせました。
    Linux to all, and to all, let freedom ring.

  10. #10
    Join Date
    May 2007
    Location
    Washington
    Beans
    911

    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.

Page 1 of 3 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •