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