From 42752eb1fa65f27da99cd60a613db1db985a9821 Mon Sep 17 00:00:00 2001 From: Olivier Refalo Date: Sun, 3 Mar 2013 10:47:10 -0500 Subject: [PATCH] coloring --- README.md | 1 + cmds/g2-abort.sh | 4 +++- cmds/g2-ci.sh | 5 +++-- cmds/g2-co.sh | 10 ++++++---- cmds/g2-continue.sh | 6 ++++-- cmds/g2-cp.sh | 4 +++- cmds/g2-g2add.sh | 4 ++-- cmds/g2-g2am.sh | 5 ++++- cmds/g2-g2brstatus.sh | 4 +++- cmds/g2-g2help.sh | 4 +++- cmds/g2-panic.sh | 2 +- cmds/g2-rb.sh | 4 +++- cmds/g2-undo.sh | 8 +++++--- cmds/g2-unfreeze.sh | 4 +++- cmds/g2-unwip.sh | 3 ++- cmds/g2-wip.sh | 3 ++- 16 files changed, 48 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 9dafc9f8..a0e914b5 100644 --- a/README.md +++ b/README.md @@ -422,6 +422,7 @@ Distributed under the GNU General Public License, version 2.0. ## FIXED / DONE +* Many commands are now colorized * Added tips of the day * fix issue with --set-upstream being deprecated * fix warning when running: g track diff --git a/cmds/g2-abort.sh b/cmds/g2-abort.sh index 4a336c97..6539f188 100755 --- a/cmds/g2-abort.sh +++ b/cmds/g2-abort.sh @@ -2,4 +2,6 @@ # # Aborts a merge or rebase -[[ ! $("$GIT_EXE" rev-parse --git-dir 2> /dev/null) ]] && echo "fatal: Not a Git Repository" || ("$GIT_EXE" merge --abort 2> /dev/null || "$GIT_EXE" rebase --abort 2> /dev/null) +source "$G2_HOME/cmds/color.sh" + +[[ ! $("$GIT_EXE" rev-parse --git-dir 2> /dev/null) ]] && echo_fatal "fatal: Not a Git Repository" || ("$GIT_EXE" merge --abort 2> /dev/null || "$GIT_EXE" rebase --abort 2> /dev/null) diff --git a/cmds/g2-ci.sh b/cmds/g2-ci.sh index 5a65fa46..61fb8e66 100755 --- a/cmds/g2-ci.sh +++ b/cmds/g2-ci.sh @@ -1,6 +1,7 @@ #!/bin/bash # # +source "$G2_HOME/cmds/color.sh" -[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: WIP detected, please first." && exit 1 -[[ $("$GIT_EXE" diff --cached --numstat | wc -l) -eq 0 ]] && echo "fatal: No files to commit, please changes first." || "$GIT_EXE" commit -u "$@" +[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: WIP detected, please first." && exit 1 +[[ $("$GIT_EXE" diff --cached --numstat | wc -l) -eq 0 ]] && echo_fatal "fatal: No files to commit, please changes first." || "$GIT_EXE" commit -u "$@" diff --git a/cmds/g2-co.sh b/cmds/g2-co.sh index 84007357..030818af 100755 --- a/cmds/g2-co.sh +++ b/cmds/g2-co.sh @@ -1,9 +1,11 @@ #!/bin/bash # +source "$G2_HOME/cmds/color.sh" + hasChanges() { - [[ $("$GIT_EXE" diff --cached --numstat | wc -l) -ne 0 ]] && echo "fatal: staged changed detected, please commit or them." && exit 1 - [[ $("$GIT_EXE" diff --numstat | wc -l) -ne 0 ]] && echo "fatal: some files were changed in this branch, either commit , or ." && exit 1 + [[ $("$GIT_EXE" diff --cached --numstat | wc -l) -ne 0 ]] && echo_fatal "fatal: staged changed detected, please commit or them." && exit 1 + [[ $("$GIT_EXE" diff --numstat | wc -l) -ne 0 ]] && echo_fatal "fatal: some files were changed in this branch, either commit , or ." && exit 1 } isBranch=$("$GIT_EXE" branch -a | grep -c "$1") @@ -15,6 +17,6 @@ isBranch=$("$GIT_EXE" branch -a | grep -c "$1") exit $?; } -echo "There is no branch called '$1', you may want to run 'g fetch ' to refresh from the server" -echo "If you are trying to revert a file, consider 'g undo '" +echo_info "There is no branch called '$1', you may want to run 'g fetch ' to refresh from the server" +echo_info "If you are trying to revert a file, consider 'g undo '" diff --git a/cmds/g2-continue.sh b/cmds/g2-continue.sh index e6a5f8e2..75686219 100755 --- a/cmds/g2-continue.sh +++ b/cmds/g2-continue.sh @@ -4,13 +4,15 @@ # Unlike git, it detects what needs to be resumed: rebase or merge # and smartly run the right command +source "$G2_HOME/cmds/color.sh" + state=$("$GIT_EXE" g2brstatus) [[ $state = "rebase" ]] && { action="--continue" if git diff-index --quiet HEAD --; then - echo "The last commit brings no significant changes -- skipping" + echo_info "The last commit brings no significant changes -- skipping" action="--skip" fi @@ -21,5 +23,5 @@ state=$("$GIT_EXE" g2brstatus) [[ $state = "merge" ]] && { # Count the number of unmerged files count=$("$GIT_EXE" ls-files --unmerged | wc -l) - [[ $count -ne 0 ]] && echo "I am afraid you still have unmerged files, please run to resolv conflicts" ||"$GIT_EXE" commit + [[ $count -ne 0 ]] && echo_fatal "I am afraid you still have unmerged files, please run to resolve conflicts" ||"$GIT_EXE" commit } \ No newline at end of file diff --git a/cmds/g2-cp.sh b/cmds/g2-cp.sh index b1369d85..39682eca 100755 --- a/cmds/g2-cp.sh +++ b/cmds/g2-cp.sh @@ -2,5 +2,7 @@ # # Cherry picking, but forbids anything on top of wip commit -[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: Cherry Picking on a WIP commit is forbiden, please and commit " && exit 1 +source "$G2_HOME/cmds/color.sh" + +[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: Cherry Picking on a WIP commit is forbiden, please and commit " && exit 1 "$GIT_EXE" cherry-pick "$@" \ No newline at end of file diff --git a/cmds/g2-g2add.sh b/cmds/g2-g2add.sh index cc2cf940..1dc9a8ca 100755 --- a/cmds/g2-g2add.sh +++ b/cmds/g2-g2add.sh @@ -1,4 +1,4 @@ #!/bin/bash # - -echo "You don't with G2, you and " +source "$G2_HOME/cmds/color.sh" +echo_fatal "Don't use with G2, and are powerfull commands" \ No newline at end of file diff --git a/cmds/g2-g2am.sh b/cmds/g2-g2am.sh index 27cb99fe..19228a9b 100755 --- a/cmds/g2-g2am.sh +++ b/cmds/g2-g2am.sh @@ -1,8 +1,11 @@ #!/bin/bash # +source "$G2_HOME/cmds/color.sh" + + error() { - echo $1 + echo_fatal $1 exit 1 } diff --git a/cmds/g2-g2brstatus.sh b/cmds/g2-g2brstatus.sh index b9c18758..763d6889 100755 --- a/cmds/g2-g2brstatus.sh +++ b/cmds/g2-g2brstatus.sh @@ -2,9 +2,11 @@ # # Internal command that return "rebase", "merge" or "false" +source "$G2_HOME/cmds/color.sh" + GDIR=$("$GIT_EXE" rev-parse --git-dir 2> /dev/null) -[[ ! $GDIR ]] && echo "fatal: Not a Git Repository" && exit 1 +[[ ! $GDIR ]] && echo_fatal "fatal: Not a Git Repository" && exit 1 [[ -d "$GDIR/rebase-merge" || -d "$GDIR/rebase-apply" ]] && echo "rebase" && exit 0 [[ -f "$GDIR/MERGE_HEAD" ]] && echo "merge" && exit 0 echo "false" diff --git a/cmds/g2-g2help.sh b/cmds/g2-g2help.sh index c82d01f6..7d3b8771 100755 --- a/cmds/g2-g2help.sh +++ b/cmds/g2-g2help.sh @@ -1,7 +1,9 @@ #!/bin/bash # -echo "You can find all necessary help at http://orefalo.github.com/g2 & http://www.github.com/orefalo/g2" +source "$G2_HOME/cmds/color.sh" + +echo -e "You can find all necessary help at ${boldon}http://orefalo.github.com/g2${boldoff} & ${boldon}http://www.github.com/orefalo/g2${reset}" if [ $(uname -s) = "Darwin" ]; then open "http://orefalo.github.com/g2" diff --git a/cmds/g2-panic.sh b/cmds/g2-panic.sh index 33850c35..c11824e1 100755 --- a/cmds/g2-panic.sh +++ b/cmds/g2-panic.sh @@ -1,7 +1,7 @@ #!/bin/bash # -read -p "Remove all un-tracked files and checkout HEAD, are you sure (y/n)? " -n 1 -r +read -p "This action will discard all work in progress and checkout HEAD, are you sure (y/n)? " -n 1 -r [[ $REPLY == [yY]* ]] && { echo "$GIT_EXE" abort diff --git a/cmds/g2-rb.sh b/cmds/g2-rb.sh index 9d0d003f..280de692 100755 --- a/cmds/g2-rb.sh +++ b/cmds/g2-rb.sh @@ -1,6 +1,8 @@ #!/bin/bash # +source "$G2_HOME/cmds/color.sh" + # substitute "upstream" with real upstream name declare -a v=("$@") declare i=0 @@ -8,7 +10,7 @@ for a in "${v[@]}" do [[ "$a" = "upstream" ]] && { remote=$("$GIT_EXE" g2getremote) - [[ -z $remote ]] && echo "fatal: upstream not found, please setup tracking for this branch, ie. " && exit 1 + [[ -z $remote ]] && echo_fatal "fatal: upstream not found, please setup tracking for this branch, ie. " && exit 1 set -- "${@:1:$i}" "origin/master" "${@:($i+2)}"; } && break let i++ diff --git a/cmds/g2-undo.sh b/cmds/g2-undo.sh index 31fa1481..d4b9235a 100755 --- a/cmds/g2-undo.sh +++ b/cmds/g2-undo.sh @@ -2,9 +2,11 @@ # # easy undo a file, a commit or a merge +source "$G2_HOME/cmds/color.sh" + if [ $# -lt 1 ] then - echo "Usage : g undo " + echo_info "Usage : g undo " exit fi @@ -16,12 +18,12 @@ case "$1" in "commit") #TODO: Validate local commits - echo "Undoing last commit and reverting changes to the staging area." + echo_info "Undoing last commit and reverting changes to the staging area." "$GIT_EXE" reset --soft HEAD^ ;; "merge") #TODO: Validate local commits - echo "Reverting back prior to the last merge." + echo_info "Reverting back prior to the last merge." "$GIT_EXE" reset --hard ORIG_HEAD ;; *) diff --git a/cmds/g2-unfreeze.sh b/cmds/g2-unfreeze.sh index c92e6184..980e985b 100755 --- a/cmds/g2-unfreeze.sh +++ b/cmds/g2-unfreeze.sh @@ -1,7 +1,9 @@ #!/bin/bash # -([[ -z "$@" ]] && ("$GIT_EXE" reset -q HEAD > /dev/null || echo "fatal: first commit must be unfrozen file by file.") || ("$GIT_EXE" reset -q HEAD -- $@ > /dev/null || "$GIT_EXE" rm -q --cached $@)) +source "$G2_HOME/cmds/color.sh" + +([[ -z "$@" ]] && ("$GIT_EXE" reset -q HEAD > /dev/null || echo_fatal "fatal: first commit must be unfrozen file by file.") || ("$GIT_EXE" reset -q HEAD -- $@ > /dev/null || "$GIT_EXE" rm -q --cached $@)) "$GIT_EXE" status -s; diff --git a/cmds/g2-unwip.sh b/cmds/g2-unwip.sh index b3e68731..e87bcafa 100755 --- a/cmds/g2-unwip.sh +++ b/cmds/g2-unwip.sh @@ -1,4 +1,5 @@ #!/bin/bash # +source "$G2_HOME/cmds/color.sh" -[[ $("$GIT_EXE" g2iswip) = "false" ]] && echo "fatal: there is nothing to ..." || ("$GIT_EXE" log -n 1 | grep -q -c wip && "$GIT_EXE" reset HEAD~1) +[[ $("$GIT_EXE" g2iswip) = "false" ]] && echo_fatal "fatal: there is nothing to ..." || ("$GIT_EXE" log -n 1 | grep -q -c wip && "$GIT_EXE" reset HEAD~1) diff --git a/cmds/g2-wip.sh b/cmds/g2-wip.sh index 7fed2f2f..f2d6cc10 100755 --- a/cmds/g2-wip.sh +++ b/cmds/g2-wip.sh @@ -1,8 +1,9 @@ #!/bin/bash # +source "$G2_HOME/cmds/color.sh" if [[ $("$GIT_EXE" g2iswip) = "true" ]]; then - echo "info: amending previous wip commit..." + echo_info "info: amending previous wip commit..." "$GIT_EXE" g2am else "$GIT_EXE" freeze -m wip