Here is a way:
in your home directory:
Code: Select all
nano .bashrc
This will pop .bashrc with a content that could looke like this:
Code: Select all
# .bashrc
# User specific aliases and functions
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
or PSI= etc etc.
Now comment out everything in the file with # so it looks like this:
Code: Select all
# .bashrc
# User specific aliases and functions
# Source global definitions
#if [ -f /etc/bashrc ]; then
# . /etc/bashrc
#fi
Now copy this in to the file below the lines you commented out:
Code: Select all
bash_prompt_cmd() {
RTN=$?
smiley() {
if [ $1 == 0 ] ; then
echo ":)"
else
echo ":("
fi
}
smileyc() {
if [ $1 == 0 ] ; then
echo $GREEN
else
echo $RED
fi
}
if [ $(tput colors) -gt 0 ] ; then
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
RST=$(tput op)
fi
smiley=$(smiley $RTN)
smileyc=$(smileyc $RTN)
local CY="\[\e[1;31m\]" # Each is 12 chars long
local BL="\[\e[1;34m\]"
local WH="\[\e[1;37m\]"
local BR="\[\e[0;33m\]"
local RE="\[\e[1;31m\]"
local PROMPT="${CY}$"
[ $UID -eq "0" ] && PROMPT="${RE}#"
# Add the first part of the prompt: username,host, and time
local PROMPT_PWD=""
local PS1_T1="$BL.:[ $CY`whoami`@`hostname` $BL: $CY\t $BL:$CY "
local ps_len=$(( ${#PS1_T1} - 12 * 6 + 6 + 4 )) #Len adjust for colors, time and var
local PS1_T2=" $BL]:.\n\[\$smileyc\]\$smiley\[$RST\] "
local startpos=""
PROMPT_PWD="${PWD/#$HOME/~}"
local overflow_prefix="..."
local pwdlen=${#PROMPT_PWD}
local maxpwdlen=$(( COLUMNS - ps_len ))
# Sometimes COLUMNS isn't initiliased, if it isn't, fall back on 80
[ $maxpwdlen -lt 0 ] && maxpwdlen=$(( 80 - ps_len ))
if [ $pwdlen -gt $maxpwdlen ] ; then
startpos=$(( $pwdlen - maxpwdlen + ${#overflow_prefix} ))
PROMPT_PWD="${overflow_prefix}${PROMPT_PWD:$startpos:$maxpwdlen}"
fi
export PS1="${PS1_T1}${PROMPT_PWD}${PS1_T2}"
smiley=$(smiley $RTN)
smileyc=$(smileyc $RTN)
local CY="\[\e[1;31m\]" # Each is 12 chars long
local BL="\[\e[1;34m\]"
local WH="\[\e[1;37m\]"
local BR="\[\e[0;33m\]"
local RE="\[\e[1;31m\]"
local PROMPT="${CY}$"
[ $UID -eq "0" ] && PROMPT="${RE}#"
# Add the first part of the prompt: username,host, and time
local PROMPT_PWD=""
local PS1_T1="$BL.:[ $CY`whoami`@`hostname` $BL: $CY\t $BL:$CY "
local ps_len=$(( ${#PS1_T1} - 12 * 6 + 6 + 4 )) #Len adjust for colors, time and var
local PS1_T2=" $BL]:.\n\[\$smileyc\]\$smiley\[$RST\] "
local startpos=""
PROMPT_PWD="${PWD/#$HOME/~}"
local overflow_prefix="..."
local pwdlen=${#PROMPT_PWD}
local maxpwdlen=$(( COLUMNS - ps_len ))
# Sometimes COLUMNS isn't initiliased, if it isn't, fall back on 80
[ $maxpwdlen -lt 0 ] && maxpwdlen=$(( 80 - ps_len ))
if [ $pwdlen -gt $maxpwdlen ] ; then
startpos=$(( $pwdlen - maxpwdlen + ${#overflow_prefix} ))
PROMPT_PWD="${overflow_prefix}${PROMPT_PWD:$startpos:$maxpwdlen}"
fi
export PS1="${PS1_T1}${PROMPT_PWD}${PS1_T2}"
}
PROMPT_COMMAND=bash_prompt_cmd
This is my favorite. It gives a nice and clean overview where you are in your navigation and it has a smiley system. Green smile for the right code, and if you enter the wrong code you get a red smiley.
I have tested it both in Arch (Installed cope-git first) and Mandriva.
It looks like this:
If you want the same (or a different) effect on the root prompt; just create .bashrc in /root and put the content there.
If you like it let me know. Or post your favourite!
(PS this is not going to look great in Mandriva as root user)
Good luck.