Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: HOWTO: nice BASH prompt

  1. #1
    Join Date
    Mar 2005
    Beans
    35

    HOWTO: nice BASH prompt

    1)first of all - backup your .bashrc file
    cp .bashrc .bashrc-backup
    2)now edit .bashrc with your editor:
    gedit .bashrc
    search for lines that contain the string: PS1
    and comment them (with # before them).

    in the end of the file add:
    PROMPT_HOSTNAME='SET_HERE'
    PROMPT_COLOR='1;37m'
    PROMPT_COLOR2='1;32m'

    PS1='\e[${PROMPT_COLOR}[\e[${PROMPT_COLOR2}\u@${PROMPT_HOSTNAME}\e[${PROMPT_COLOR}] $ '
    the first color is for the normal font and barckets, and the second one is for the user name and host



    I choosed green and white. you can change the first number to any of the following:

    30: Black/Dark grey
    31: Red
    32: Green
    33: Yellow
    34: Blue
    35: Magenta
    36: Fuscia
    37: White/light grey
    38: "Default" foreground color
    in the exmaple "1;37m" you will have to change the 37 to another number.
    the 1 before it can be set into zero, it is for light \ dark colors

    rename the PROMPT_HOSTNAME to your hostname (or anything you want)
    and save the file.
    pray for your god and open bash, it should work.

    it should be like this:
    http://www.base17.hostorm.biz/Bash.png

    EDIT: I have updated the pic. I used a new PS1
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\e[${PROMPT_COLOR2}\u@\h\[\033[00m\]:\[\033[1;37m\]\w\[\033[00m\]\$ '

    it is not perfect yet, play with the colors and stuff as much as you want.

    another one:
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\e[${PROMPT_COLOR2}\u@\h\[\033[00m\]:\[\033[1;37m\]\w\[\033[00m\]\$ '

    i think this is the nicest until now

    for more info:
    http://www.neowin.net/forum/lofivers...p/t148706.html
    http://networking.ringofsaturn.com/U...sh-prompts.php

    good luck
    Last edited by seven; May 2nd, 2005 at 07:02 PM.
    (\ /)
    (O.o)
    (> <)

    This is Bunny. Copy Bunny into your signature to help him on his way to world domination

  2. #2
    Join Date
    Dec 2004
    Location
    Finland
    Beans
    398

    Re: HOWTO: nice BASH prompt

    Good HOWTO. Here's another good prompt:
    Code:
    PS1='\n\[\033[1;34m\]\342\226\210\342\226\210 \u @ \w\n\[\033[0;36m\]\342\226\210\342\226\210 \t $ \[\033[0;39m\]'
    The colorblocks and the newline before the prompt should make it easy to quickly visualize the prompts at a longer console output. For root, I have the same with red and violet and $ replaced with #.



    Edit:
    Using those colorblock characters seems to cause weird behaviour for backspace and delete. Not good after all.
    Last edited by ow50; May 11th, 2005 at 05:16 PM.

  3. #3
    Join Date
    Apr 2005
    Beans
    214
    Distro
    Edgy Eft Testing

    Re: HOWTO: nice BASH prompt

    Here's a helper file I use for this, I can't remember where I got it, or if it's complete, but it has mnemonics for a bunch of colors, which will make this easier. I put it in ~/bin/ansicolor, so I can source ~/bin/ansicolor in scripts I want to add color to.

    Code:
    C_RED="\[\033[0;31m\]"
    C_GREEN="\[\033[0;32m\]"
    C_LIGHT_GRAY="\[\033[0;37m\]"
    C_RESET="\[\033[0m\]"
    
    C_BROWN="\[\033[0;33m\]"
    C_BLUE="\[\033[0;34m\]"
    C_PURPLE="\[\033[0;35m\]"
    C_CYAN="\[\033[0;36m\] "
    C_GRAY="\[\033[1;30m\]"
    C_WHITE="\[\033[1;37m\]"
    C_YELLOW="\[\033[1;33m\]"
    
    C_LIGHT_BLUE="\[\033[1;34m\]"
    C_LIGHT_CYAN="\[\033[1;36m\]"
    C_LIGHT_PURPLE="\[\033[1;35m\]"
    C_LIGHT_RED="\[\033[1; 31m\]"
    C_LIGHT_GREEN="\[\033[1;32m\]"
    Edit: BTW, my prompt is this:
    Code:
    PS1="$C_BLUE[$C_RED\$?$C_BLUE][$C_RED\u@\h:\w$C_BLUE]\$ $C_RESET"
    Last edited by JonahRowley; May 2nd, 2005 at 08:16 PM.

  4. #4
    Join Date
    Apr 2005
    Location
    Kuopio, Finland
    Beans
    128
    Distro
    Xubuntu 10.10 Maverick Meerkat

    Re: HOWTO: nice BASH prompt

    Thanks for the HOWTO.

    Mine bash: http://www.roskakori.org/juippis/pic...shots/bash.png

    And the line:
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w\[\033[01;34m\] \$\[\033[00m\] '

    Heh, tried to make it "Gentoo-like"

  5. #5
    Join Date
    Jan 2005
    Beans
    43
    Distro
    Dapper Drake Testing/

    Re: HOWTO: nice BASH prompt

    brilliant stuff. it's so pretty now =). Many thanks for the HOWTO

  6. #6
    Join Date
    Apr 2005
    Location
    Sintra, Portugal
    Beans
    835

    Thumbs up Re: HOWTO: nice BASH prompt

    I was just thinking, after using bash, that I should search on how to change the prompt - so here it is!

    Thanks a lot to you all here. All your suggestions are useful.

  7. #7
    Join Date
    Mar 2005
    Beans
    115

    Re: HOWTO: nice BASH prompt

    I'm using this line:
    Code:
    PROMPT_COLOR='1;32m'
    PROMPT_COLOR2='1;32m'
    PROMPT_COLOR3='1;34m'
    
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\e[${PROMPT_COLOR2}\u\033[01;32m\e[${PROMPT_COLOR3}@\033[01;32m\e[${PROMPT_COLOR}\h\[\033[1;31m\]:\[\033[1;34m\]\w\[\033[1;31m\]\$\033[00m'
    See attachment for what it does
    Attached Images Attached Images
    "Windows is something to overcome"

    Howto's by me:
    Tweak firefox! (URL now works..)
    Backup/Restore your system!
    Avoid having to reboot


    Compentux.org
    , the Linux Tip & Howto gathering initiative!

  8. #8
    Join Date
    Jan 2005
    Beans
    43
    Distro
    Dapper Drake Testing/

    Re: HOWTO: nice BASH prompt

    Edit:
    Using those colorblock characters seems to cause weird behaviour for backspace and delete. Not good after all.
    Here's something that works. The font colour and style is the same, just not the colour thing at the beginning.

    PS1='\n\[\033[01;34m\]\u @ \w\n\[\033[0;36m\]\t $ \[\033[0;39m\]'

  9. #9
    Join Date
    Mar 2005
    Location
    United Kingdom
    Beans
    15

    Re: HOWTO: nice BASH prompt

    Here's what I use:

    Code:
    function jobcount {
       jobs | wc -l | tr -d " "
    }
    
    cur_tty=$(tty | sed -e "s/.*tty\(.*\)/\1/")
    
    loadavg=$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\1/" -e "s/ //g")
    
    # PROMPT
    
    PS1='\[\033[1;44m\]\[\033[1;34m\]  \[\033[1;40m\] [\u@\h:\w]\n\[\033[1;44m\]\[\033[1;34m\]  \[\033[1;40m\] [j:`jobcount`, t:$cur_tty, l:$loadavg]\n\[\033[1;46m\]\[\033[1;36m\]  \[\033[1;40m\] [`date +%D` \t] $> \[\033[0;39m\]'
    Three-line hack of the colorblocks prompt. It displays:
    1st line: the usual. user@host:directory
    2nd line: suspended jobs, tty name and most recent load average.
    3rd line: The actual prompt. Just the date and time, and a different kind of prompt character.

    Wow, this terminal OWNS now. Shove that in your "C:\>" and smoke it, Win nuts!
    Attached Images Attached Images

  10. #10
    Join Date
    Apr 2005
    Location
    Sweden
    Beans
    24

    Re: HOWTO: nice BASH prompt

    Quote Originally Posted by Heliode
    I'm using this line:
    Code:
    PROMPT_COLOR='1;32m'
    PROMPT_COLOR2='1;32m'
    PROMPT_COLOR3='1;34m'
    
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\e[${PROMPT_COLOR2}\u\033[01;32m\e[${PROMPT_COLOR3}@\033[01;32m\e[${PROMPT_COLOR}\h\[\033[1;31m\]:\[\033[1;34m\]\w\[\033[1;31m\]\$\033[00m'
    See attachment for what it does
    Heh. This thread is such a perfect example of what is wrong with bash. Just look at that PS1 line. It is a completely needless second language within bash, and a 100% unreadable, unmaintanable mess of a language at that. What is wrong with simply specifying a function whose output becomes the prompt? That is what fish does.

    Code:
    function fish_prompt
    	whoami
    	echo ' '
    	set_color green
    	echo \n\ 
    	pwd
    	set_color normal
    	echo \n\>\ 
    end
    The only caveats is that all terminal escape codes, such as those written by the set_color command to set the text color, must en with a newline in order to tell fish how long the escape code sequence is, and that newlines are ignored.

    Now tell me that this isn't an order of magnitude more readable and easy to use...

Page 1 of 2 12 LastLast

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
  •