Hot posts
recent

How to color bash prompt in Fedora

...or other linux system.

If you wish to color your command line prompt in your terminal you should edit your .bashrc file located in your home directory. For editing you can choose your favourite text editor such as vim, nano, gedit, kate, sublime text, etc. Everything in linux is just text file and that's great. :)

vim .bashrc in terminal

So for me it is command in console:
$ vim ~/.bashrc

And edit it like this:

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:

    # using tput commands
    FGBLK=$( tput setaf 0 ) # 000000
    FGRED=$( tput setaf 1 ) # ff0000
    FGGRN=$( tput setaf 2 ) # 00ff00
    FGYLO=$( tput setaf 3 ) # ffff00
    FGBLU=$( tput setaf 4 ) # 0000ff
    FGMAG=$( tput setaf 5 ) # ff00ff
    FGCYN=$( tput setaf 6 ) # 00ffff
    FGWHT=$( tput setaf 7 ) # ffffff

    BGBLK=$( tput setab 0 ) # 000000
    BGRED=$( tput setab 1 ) # ff0000
    BGGRN=$( tput setab 2 ) # 00ff00
    BGYLO=$( tput setab 3 ) # ffff00
    BGBLU=$( tput setab 4 ) # 0000ff
    BGMAG=$( tput setab 5 ) # ff00ff
    BGCYN=$( tput setab 6 ) # 00ffff
    BGWHT=$( tput setab 7 ) # ffffff

    RESET=$( tput sgr0 )
    BOLDM=$( tput bold )
    UNDER=$( tput smul )
    REVRS=$( tput rev )

if [ $EUID == 0 ]; then
  export PS1="\[$FGRED\]\u\[$FGMAG\]@\[$FGCYN\]\h \[$FGBLU\]\W\$ \[$RESET\]"
 else
  export PS1="\[$FGGRN\]\u\[$FGMAG\]@\[$FGCYN\]\h \[$FGBLU\]\W\$ \[$RESET\]"
fi


I think the code above is clear. :) So restart your terminal and you will see.

Happy coloring.
Jan Hřídel

Jan Hřídel

Copyright © 2011-2015. Ing. Jan Hřídel, All Rights Reserved. Powered by Blogger.