replace tabs indentation by spaces

This commit is contained in:
nojhan 2012-07-17 09:23:44 +02:00
parent 258ec164ef
commit e555e92f95

View File

@ -39,8 +39,8 @@
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.} bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
if [ $bmajor -lt 3 ] || [ $bmajor -eq 3 -a $bminor -lt 2 ]; then if [ $bmajor -lt 3 ] || [ $bmajor -eq 3 -a $bminor -lt 2 ]; then
unset bash bmajor bminor unset bash bmajor bminor
return return
fi fi
unset bash bmajor bminor unset bash bmajor bminor
@ -84,20 +84,20 @@ __CPUNUM=$(grep ^processor /proc/cpuinfo | wc -l)
# or attached stopped jobs (suspended with Ctrl-Z) # or attached stopped jobs (suspended with Ctrl-Z)
__jobcount_color() __jobcount_color()
{ {
running=`jobs -r | wc -l | tr -d " "` running=`jobs -r | wc -l | tr -d " "`
stopped=`jobs -s | wc -l | tr -d " "` stopped=`jobs -s | wc -l | tr -d " "`
if [ $running != "0" -a $stopped != "0" ] if [ $running != "0" -a $stopped != "0" ]
then then
rep="${NO_COL}[${YELLOW}${running}r${NO_COL}/${LIGHT_YELLOW}${stopped}s${NO_COL}]" rep="${NO_COL}[${YELLOW}${running}r${NO_COL}/${LIGHT_YELLOW}${stopped}s${NO_COL}]"
elif [ $running != "0" -a $stopped == "0" ] elif [ $running != "0" -a $stopped == "0" ]
then then
rep="${NO_COL}[${YELLOW}${running}r${NO_COL}]" rep="${NO_COL}[${YELLOW}${running}r${NO_COL}]"
elif [ $running == "0" -a $stopped != "0" ] elif [ $running == "0" -a $stopped != "0" ]
then then
rep="${NO_COL}[${LIGHT_YELLOW}${stopped}s${NO_COL}]" rep="${NO_COL}[${LIGHT_YELLOW}${stopped}s${NO_COL}]"
fi fi
echo -ne "$rep" echo -ne "$rep"
} }
###################### ######################
@ -107,10 +107,10 @@ __jobcount_color()
# Get the branch name of the current directory # Get the branch name of the current directory
__git_branch() __git_branch()
{ {
if git rev-parse --git-dir >/dev/null 2>&1 && [ ! -z "`git branch`" ]; then if git rev-parse --git-dir >/dev/null 2>&1 && [ ! -z "`git branch`" ]; then
echo -n "$(git branch 2>/dev/null | sed -n '/^\*/s/^\* //p;')" echo -n "$(git branch 2>/dev/null | sed -n '/^\*/s/^\* //p;')"
fi fi
} }
# Set a color depending on the branch state: # Set a color depending on the branch state:
@ -119,35 +119,35 @@ __git_branch()
# - red if there is changes to commit # - red if there is changes to commit
__git_branch_color() __git_branch_color()
{ {
command -v git >/dev/null 2>&1 || return 1; command -v git >/dev/null 2>&1 || return 1;
branch=$(__git_branch) branch=$(__git_branch)
if [ ! -z "$branch" ] ; then if [ ! -z "$branch" ] ; then
git diff --quiet >/dev/null 2>&1 git diff --quiet >/dev/null 2>&1
GD=$? GD=$?
git diff --cached --quiet >/dev/null 2>&1 git diff --cached --quiet >/dev/null 2>&1
GDC=$? GDC=$?
has_commit=$(git rev-list --no-merges --count origin/${branch}..${branch} 2>/dev/null) has_commit=$(git rev-list --no-merges --count origin/${branch}..${branch} 2>/dev/null)
if [ -z "$has_commit" ]; then if [ -z "$has_commit" ]; then
has_commit=0 has_commit=0
fi fi
if [ "$GD" -eq 1 -o "$GDC" -eq "1" ]; then if [ "$GD" -eq 1 -o "$GDC" -eq "1" ]; then
if [ "$has_commit" -gt "0" ] ; then if [ "$has_commit" -gt "0" ] ; then
ret=" ${RED}${branch}${NO_COL}(${YELLOW}$has_commit${NO_COL})" # changes to commit and commits to push ret=" ${RED}${branch}${NO_COL}(${YELLOW}$has_commit${NO_COL})" # changes to commit and commits to push
else else
ret=" ${RED}${branch}${NO_COL}" # changes to commit ret=" ${RED}${branch}${NO_COL}" # changes to commit
fi fi
else else
if [ "$has_commit" -gt "0" ] ; then if [ "$has_commit" -gt "0" ] ; then
# some commit(s) to push # some commit(s) to push
ret=" ${YELLOW}${branch}${NO_COL}(${YELLOW}$has_commit${NO_COL})" ret=" ${YELLOW}${branch}${NO_COL}(${YELLOW}$has_commit${NO_COL})"
else else
ret=" ${GREEN}${branch}${NO_COL}" # nothing to commit or push ret=" ${GREEN}${branch}${NO_COL}" # nothing to commit or push
fi fi
fi fi
echo -ne "$ret" echo -ne "$ret"
fi fi
} }
################## ##################
@ -158,45 +158,45 @@ __git_branch_color()
# returns 1 if no battery support # returns 1 if no battery support
__battery() __battery()
{ {
command -v acpi >/dev/null 2>&1 || return 1; command -v acpi >/dev/null 2>&1 || return 1;
bat=`acpi --battery 2>/dev/null | sed "s/^Battery .*, \([0-9]*\)%.*$/\1/"` bat=`acpi --battery 2>/dev/null | sed "s/^Battery .*, \([0-9]*\)%.*$/\1/"`
if [ "${bat}" == "" ] ; then if [ "${bat}" == "" ] ; then
return 1 return 1
fi fi
if [ ${bat} -lt 90 ] ; then if [ ${bat} -lt 90 ] ; then
echo -n "${bat}" echo -n "${bat}"
return 0 return 0
else else
return 1 return 1
fi fi
} }
# Compute a gradient of background/foreground colors depending on the battery status # Compute a gradient of background/foreground colors depending on the battery status
__battery_color() __battery_color()
{ {
bat=$(__battery) bat=$(__battery)
if [ "$?" = "1" ] ; then return; fi; # no battery support if [ "$?" = "1" ] ; then return; fi; # no battery support
if [ "$bat" != "" ] ; then if [ "$bat" != "" ] ; then
if [ ${bat} -gt 75 ]; then if [ ${bat} -gt 75 ]; then
return; # nothing displayed above 75% return; # nothing displayed above 75%
fi fi
ret="${NO_COL}[battery=" ret="${NO_COL}[battery="
if [ ${bat} -le 75 ] && [ ${bat} -gt 50 ] ; then if [ ${bat} -le 75 ] && [ ${bat} -gt 50 ] ; then
ret="${ret}${LIGHT_GREEN}" ret="${ret}${LIGHT_GREEN}"
elif [ ${bat} -le 40 ] && [ ${bat} -gt 20 ] ; then elif [ ${bat} -le 40 ] && [ ${bat} -gt 20 ] ; then
ret="${ret}${LIGHT_YELLOW}" ret="${ret}${LIGHT_YELLOW}"
elif [ ${bat} -le 20 ] && [ ${bat} -gt 10 ] ; then elif [ ${bat} -le 20 ] && [ ${bat} -gt 10 ] ; then
ret="${ret}${LIGHT_RED}" ret="${ret}${LIGHT_RED}"
elif [ ${bat} -le 10 ] && ${bat} -gt 5 ] ; then elif [ ${bat} -le 10 ] && ${bat} -gt 5 ] ; then
ret="${ret}${WARN_RED}" ret="${ret}${WARN_RED}"
else else
ret="${ret}${CRIT_RED}" ret="${ret}${CRIT_RED}"
fi fi
echo -ne "${ret}${bat}%${NO_COL}]" echo -ne "${ret}${bat}%${NO_COL}]"
fi fi
} }
@ -207,93 +207,93 @@ __battery_color()
# Get the load average # Get the load average
__load() __load()
{ {
load=$(awk '{print $1}' /proc/loadavg) load=$(awk '{print $1}' /proc/loadavg)
echo -n "$load" echo -n "$load"
} }
# Compute a gradient of background/forground colors depending on the battery status # Compute a gradient of background/forground colors depending on the battery status
__load_color() __load_color()
{ {
# Colour progression is important ... # Colour progression is important ...
# bold gray -> bold green -> bold yellow -> bold red -> # bold gray -> bold green -> bold yellow -> bold red ->
# black on red -> bold white on red # black on red -> bold white on red
# #
# Then we have to choose the values at which the colours switch, with # Then we have to choose the values at which the colours switch, with
# anything past yellow being pretty important. # anything past yellow being pretty important.
loadval=$(__load) loadval=$(__load)
load=$(echo $loadval | sed -E 's/(^0| .*|\.)//g;s/^0*//g' ) load=$(echo $loadval | sed -E 's/(^0| .*|\.)//g;s/^0*//g' )
if [ -z "$load" ]; then if [ -z "$load" ]; then
load=0 load=0
fi fi
let "load=$load/$__CPUNUM" let "load=$load/$__CPUNUM"
if [ "$load" -ge "60" ] if [ "$load" -ge "60" ]
then then
ret="${NO_COL}[" ret="${NO_COL}["
if [ $load -lt 70 ] ; then if [ $load -lt 70 ] ; then
ret="${ret}${LIGHT_GREY}" ret="${ret}${LIGHT_GREY}"
elif [ $load -ge 1 ] && [ $load -lt 80 ] ; then elif [ $load -ge 1 ] && [ $load -lt 80 ] ; then
ret="${ret}${LIGHT_GREEN}" ret="${ret}${LIGHT_GREEN}"
elif [ $load -ge 80 ] && [ $load -lt 95 ] ; then elif [ $load -ge 80 ] && [ $load -lt 95 ] ; then
ret="${ret}${LIGHT_YELLOW}" ret="${ret}${LIGHT_YELLOW}"
elif [ $load -ge 95 ] && [ $load -lt 150 ] ; then elif [ $load -ge 95 ] && [ $load -lt 150 ] ; then
ret="${ret}${LIGHT_RED}" ret="${ret}${LIGHT_RED}"
elif [ $load -ge 150 ] && [ $load -lt 200 ] ; then elif [ $load -ge 150 ] && [ $load -lt 200 ] ; then
ret="${ret}${WARN_RED}" ret="${ret}${WARN_RED}"
else else
ret="${ret}${CRIT_RED}" ret="${ret}${CRIT_RED}"
fi fi
ret="${ret}cpu=$load%${NO_COL}]" ret="${ret}cpu=$load%${NO_COL}]"
echo -ne "${ret}" echo -ne "${ret}"
fi fi
} }
__smart_prompt() __smart_prompt()
{ {
if [ "$EUID" -ne "0" ] if [ "$EUID" -ne "0" ]
then then
git log -1 >/dev/null 2>&1 git log -1 >/dev/null 2>&1
if [ "$?" -eq "0" ] if [ "$?" -eq "0" ]
then then
echo -n '±' echo -n '±'
else else
echo -n '$' echo -n '$'
fi fi
else else
echo -n '#' echo -n '#'
fi fi
} }
__return_value() __return_value()
{ {
if [ "$1" -ne "0" ] if [ "$1" -ne "0" ]
then then
echo -ne "${NO_COL}[${PURPLE}\\\$?=$1${NO_COL}]" echo -ne "${NO_COL}[${PURPLE}\\\$?=$1${NO_COL}]"
fi fi
} }
__set_bash_prompt() __set_bash_prompt()
{ {
__RETURN="`__return_value $?`" __RETURN="`__return_value $?`"
__LOAD="`__load_color`" __LOAD="`__load_color`"
__JOBS="`__jobcount_color`" __JOBS="`__jobcount_color`"
__BATT="`__battery_color`" __BATT="`__battery_color`"
__GIT="`__git_branch_color`" __GIT="`__git_branch_color`"
__PROMPT="`__smart_prompt`" __PROMPT="`__smart_prompt`"
PS1="${__BATT}${__LOAD}${__JOBS}" PS1="${__BATT}${__LOAD}${__JOBS}"
if [ "$EUID" -ne "0" ] if [ "$EUID" -ne "0" ]
then then
PS1="${PS1}${LIGHT_GREEN}\u@\h${NO_COL}:${LIGHT_BLUE}\w${NO_COL}" PS1="${PS1}${LIGHT_GREEN}\u@\h${NO_COL}:${LIGHT_BLUE}\w${NO_COL}"
PS1="${PS1}${__GIT}" PS1="${PS1}${__GIT}"
else else
PS1="${PS1}${LIGHT_RED}\u@\h${NO_COL}:${LIGHT_BLUE}\w${NO_COL}" PS1="${PS1}${LIGHT_RED}\u@\h${NO_COL}:${LIGHT_BLUE}\w${NO_COL}"
fi fi
PS1="${PS1}${__RETURN}${__PROMPT} " PS1="${PS1}${__RETURN}${__PROMPT} "
# Glue the bash prompt always go to the first column . # Glue the bash prompt always go to the first column .
# Avoid glitches after interrupting a command with Ctrl-C # Avoid glitches after interrupting a command with Ctrl-C
PS1="\[\033[G\]${PS1}${NO_COL}" PS1="\[\033[G\]${PS1}${NO_COL}"
} }
######################## ########################
# Construct the prompt # # Construct the prompt #