Bash happy prompt Kategoria: Linux | Tagi: bash, do poprawki | Autor: Bartłomiej Gałęzia

http://meinit.nl/smiley-prompt-in-bash

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;32m\]” # 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

>> ~.bashrc

after:

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it’s compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

then

#if [ "$color_prompt" = yes ]; then
#    PS1=’${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ‚
#else
#    PS1=’${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ‚
#fi
#unset color_prompt force_color_prompt

Dodaj komentarz

Brak komentarzy, bądź pierwszy i dodaj swój komentarz