Colorful prompt (PS1) di Centos dan Debian + Ubuntu

Terkadang sebagai administrator cukup membosankan juga di depan “Black Screen” berjam-jam terkadang lebih dari 12 jam sehari, nah supaya tidak bosan dan suntuk silahkan aja utak-atik prompt bash kita supaya yang hitam menjadi berwarna hahahaha…. yang mana sebelumnya dengan tampilan

root@domain #

menjadi

root@domain #

cukup dengan meng-edit file /root/.bashrc menggunakan vi, vim, nano

dan tambahkan baris berikut (Centos);

export PS1="\[\033[1;33m\]\u\[\033[1;37m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;36m\]\\$ \[\033[0m\]";

Sedangkan untuk Debian dan Ubuntu bisa dengan meng-copy;

# This file attempts to add color to command shells
 
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi
 
# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS.  Try to use the external file
# first to take advantage of user additions.  Use internal bash
# globbing instead of external grep binary.
use_color=false
safe_term=${TERM//[^[:alnum:]]/?}   # sanitize TERM
match_lhs=""
[[ -f ~/.dir_colors   ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
[[ -z ${match_lhs}    ]] \
        && type -P dircolors >/dev/null \
        && match_lhs=$(dircolors --print-database)
[[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true
 
if ${use_color} ; then
        # Enable colors for ls, etc.  Prefer ~/.dir_colors #64489
        if type -P dircolors >/dev/null ; then
                if [[ -f ~/.dir_colors ]] ; then
                        eval $(dircolors -b ~/.dir_colors)
                elif [[ -f /etc/DIR_COLORS ]] ; then
                        eval $(dircolors -b /etc/DIR_COLORS)
                fi
        fi
 
        if [[ ${EUID} == 0 ]] ; then
                PS1='${debian_chroot:+($debian_chroot)}\[\033[01;33m\]\u\[\033[01;34m\]@\[\033[01;32m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
        else
                PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u\[\033[01;34m\]@\[\033[01;32m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
        fi
 
        alias ls='ls --color=auto'
        alias grep='grep --colour=auto'
else
        PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
 
# Try to keep environment pollution down, EPA loves us.
unset use_color safe_term match_lhs

Selamat mencoba dan mudah-mudahan tidak bosan lagi dengan “Black Screen” hehehe,

Sebetulnya dengan menggunakan;

export PS1="\[\033[1;33m\]\u\[\033[1;37m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;36m\]\\$ \[\033[0m\]";

untuk semua linux juga bisa dan scripts colorful untuk debian dan ubuntu itu hanya untuk variasi saja…

Kalau mau bikin sendiri silahkan baca https://wiki.archlinux.org/index.php/Color_Bash_Prompt

Merdekaaa……

Author: yonaldi on April 21, 2011
Category: Knowledge

Leave a Reply

Last articles