Skip to content

Commit

Permalink
Merge pull request #37 from apjanke/handle-no-terminal
Browse files Browse the repository at this point in the history
Fix handling of no-tty or no-color-support cases
  • Loading branch information
kamranahmedse committed Apr 26, 2016
2 parents e88b2f5 + 1c24978 commit c434510
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions git-standup
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash

set -e

## Get the options and store them in variables
while getopts "d::a::w::" opt; do
Expand All @@ -12,20 +13,19 @@ if [[ ! $option_a ]] && [[ ! $option_d ]] && [[ ! $option_w ]] && [[ $# -gt 0 ]
exit 1
fi

{
# Use colors, but only if connected to a terminal, and that terminal
# supports them.
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [[ -t 1 ]] && [[ -n "$ncolors" ]] && [[ "$ncolors" -ge 8 ]] ; then
# Use colors, but only if connected to a terminal, and that terminal
# supports them.
if [[ -t 1 ]] && [[ -n "$TERM" ]] && which tput &>/dev/null && tput colors &>/dev/null; then
ncolors=$(tput colors)
if [[ -n "$ncolors" ]] && [[ "$ncolors" -ge 8 ]] ; then
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
BOLD=$(tput bold)
UNDERLINE=$(tput smul)
NORMAL=$(tput sgr0)
GIT_PRETTY_FORMAT='%Cred%h%Creset - %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
else
RED=""
GREEN=""
Expand All @@ -34,22 +34,9 @@ fi
BOLD=""
UNDERLINE=""
NORMAL=""
GIT_PRETTY_FORMAT='%h - %s (%cr) <%an>'
fi
} || {
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
UNDERLINE=""
NORMAL=""
}


# Only enable exit-on-error after the non-critical colorization stuff,
# which may fail on systems lacking tput or terminfo
set -e

fi

## Set the necessary variables for standup
AUTHOR=`git config user.name`
Expand All @@ -66,7 +53,7 @@ if [[ $option_a ]] ; then
fi


## If -d flag is there, use it's value for the since
## If -d flag is there, use its value for the since
if [[ $option_d ]] && [[ $option_d -ne 0 ]] ; then
SINCE="$option_d days ago"
else
Expand All @@ -93,7 +80,7 @@ GIT_LOG_COMMAND="git --no-pager log \
--author=\"$AUTHOR\"
--abbrev-commit
--oneline
--pretty=format:'%Cred%h%Creset - %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"
--pretty=format:'$GIT_PRETTY_FORMAT'"


## For when the command has been run in a non-repo directory
Expand Down

0 comments on commit c434510

Please sign in to comment.