Merge pull request #465 from spacewander/fix-color

Fix color
This commit is contained in:
hemanth.hm 2015-10-10 09:42:55 +05:30
commit dfe0c79f45
2 changed files with 24 additions and 16 deletions

View file

@ -2,6 +2,8 @@
tmp=$(git_extra_mktemp)
above=0
# if the output won't be printed to tty, disable the color
test -t 1 && to_tty=true
color=
#
@ -56,15 +58,19 @@ active_days() {
#
color_for() {
if [ $1 -gt 200 ]; then color="$(tputq setaf 1)$(tputq bold)"
elif [ $1 -gt 150 ]; then color="$(tputq setaf 1)" # red
elif [ $1 -gt 125 ]; then color="$(tputq setaf 2)$(tputq bold)"
elif [ $1 -gt 100 ]; then color="$(tputq setaf 2)" # green
elif [ $1 -gt 75 ]; then color="$(tputq setaf 93)$(tputq bold)"
elif [ $1 -gt 50 ]; then color="$(tputq setaf 93)" # purplish
elif [ $1 -gt 25 ]; then color="$(tputq setaf 3)$(tputq bold)"
elif [ $1 -gt 10 ]; then color="$(tputq setaf 3)" # yellow
else color="$(tputq sgr0)" # default color
if [ "$to_tty" = true ]; then
if [ $1 -gt 200 ]; then color="$(tputq setaf 1)$(tputq bold)"
elif [ $1 -gt 150 ]; then color="$(tputq setaf 1)" # red
elif [ $1 -gt 125 ]; then color="$(tputq setaf 2)$(tputq bold)"
elif [ $1 -gt 100 ]; then color="$(tputq setaf 2)" # green
elif [ $1 -gt 75 ]; then color="$(tputq setaf 93)$(tputq bold)"
elif [ $1 -gt 50 ]; then color="$(tputq setaf 93)" # purplish
elif [ $1 -gt 25 ]; then color="$(tputq setaf 3)$(tputq bold)"
elif [ $1 -gt 10 ]; then color="$(tputq setaf 3)" # yellow
else color="$(tputq sgr0)" # default color
fi
else
color=""
fi
}
@ -76,7 +82,8 @@ effort() {
path=$1
local commit_dates
local color reset_color commits len dot f_dot i msg active
reset_color="$(tputq sgr0)"
reset_color=""
test "$to_tty" = true && reset_color="$(tputq sgr0)"
commit_dates=`dates "$path"`
[ $? -gt 0 ] && exit 255
@ -191,6 +198,7 @@ export -f color_for
export -f active_days
export -f dates
export -f tputq
export to_tty
export above
export log_args

View file

@ -1,10 +1,10 @@
#!/usr/bin/env bash
COLOR_RED() { echo -en "\033[31m"; }
COLOR_GREEN() { echo -en "\033[32m"; }
COLOR_YELLOW(){ echo -en "\033[33m"; }
COLOR_BLUE() { echo -en "\033[34m"; }
COLOR_RESET() { echo -en "\033[0m"; }
COLOR_RED() { test -t 1 && echo -n "$(tput setaf 1)"; }
COLOR_GREEN() { test -t 1 && echo -n "$(tput setaf 2)"; }
COLOR_YELLOW(){ test -t 1 && echo -n "$(tput setaf 3)"; }
COLOR_BLUE() { test -t 1 && echo -n "$(tput setaf 4)"; }
COLOR_RESET() { test -t 1 && echo -n "$(tput sgr 0)"; }
function _test_git_scp()
{
@ -170,7 +170,7 @@ function _error()
case $(basename $0) in
git-scp)
case $1 in
''|-h|?|help|--help) shift; _test_git_scp; _usage $@;;
''|-h|'?'|help|--help) shift; _test_git_scp; _usage $@;;
*) scp_and_stage $@;;
esac
;;