Skip to content

Commit

Permalink
Merge pull request tj#465 from spacewander/fix-color
Browse files Browse the repository at this point in the history
Fix color
  • Loading branch information
hemanth committed Oct 10, 2015
2 parents 96e86a8 + 1d7e07e commit 72b5c17
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
28 changes: 18 additions & 10 deletions bin/git-effort
Original file line number Diff line number Diff line change
Expand Up @@ -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=

#
Expand Down Expand Up @@ -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
}

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions bin/git-scp
Original file line number Diff line number Diff line change
@@ -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()
{
Expand Down Expand Up @@ -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
;;
Expand Down

0 comments on commit 72b5c17

Please sign in to comment.