Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

many coloring changes and enhancements

  • Loading branch information...
commit c21d177ab7710745bf8c676f5fe1132a144baecc 1 parent c2e2284
@orefalo authored
View
6 cmds/color.sh
@@ -23,4 +23,10 @@ g2_initializeANSI
echo_fatal()
{
echo -e "${redf}$1${reset}";
+}
+
+
+echo_info()
+{
+echo -e "${boldon}$1${reset}";
}
View
6 cmds/g2-g2help.sh
@@ -1,4 +1,8 @@
#!/bin/bash
#
-echo "You can find all necessary help at http://orefalo.github.com/g2 & http://www.github.com/orefalo/g2"
+echo "You can find all necessary help at http://orefalo.github.com/g2 & http://www.github.com/orefalo/g2"
+
+if [ $(uname -s) = "Darwin" ]; then
+ open "http://orefalo.github.com/g2"
+fi
View
17 cmds/g2-g2pull.sh
@@ -1,19 +1,26 @@
#!/bin/bash
#
+source "$G2_HOME/cmds/color.sh"
+
error() {
- echo "fatal: use <sync> to synchronize the current branch"
- echo "remember, <sync>hing applies to the working branch, <pull>ing applies when merging feature branches."
+ echo_fatal "fatal: use <sync> to synchronize the current branch"
+ echo_info "remember, <sync>hing applies to the working branch, <pull>ing applies when merging feature branches."
+ exit 1
+}
+
+usage() {
+ echo_fatal "Usage: pull <?opts> <remote> <branch>"
exit 1
}
n=$#;
[[ $n -eq 0 || ${!n} = -* ]] && error
-[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: pulling on a wip commit is forbidden, please <unwip> and commit <ci>" && exit 1
-[[ ${!n} = */* ]] && echo "Usage: pull <?opts> <remote> <branch>" && exit 1
+[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: pulling on a wip commit is forbidden, please <unwip> and commit <ci>" && exit 1
+[[ ${!n} = */* ]] && usage
branch=${!n}
let n--
-[[ n -gt 0 && ${!n} != -* ]] && rmt=${!n} || { echo "Usage: pull <remote> <branch>" && exit 1; }
+[[ n -gt 0 && ${!n} != -* ]] && rmt=${!n} || usage
to="$rmt/$branch"
remote=$("$GIT_EXE" g2getremote)
if [[ -z $remote ]]; then
View
15 cmds/g2-g2push.sh
@@ -4,8 +4,15 @@
# forbids wip commits from being pushed
# forbids push to the working branch
+source "$G2_HOME/cmds/color.sh"
+
error() {
- echo "fatal: sorry you can't use <push> in this context, please use the <sync> command to synchronize the current branch"
+ echo_fatal "fatal: sorry you can't use <push> in this context, please use the <sync> command to synchronize the current branch"
+ exit 1
+}
+
+usage() {
+ echo_fatal "Usage: push <?opts> <remote> <branch>"
exit 1
}
@@ -24,7 +31,7 @@ hasFFlag() {
fflg=$( hasFFlag "$@" )
n=$#;
[[ $fflg = "false" && $n -eq 0 ]] && error
-[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: pushing a wip commit is forbiden, please <unwip> and commit <ci>" && exit 1
+[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: pushing a wip commit is forbiden, please <unwip> and commit <ci>" && exit 1
[[ $fflg = "true" ]] && {
read -p "warning: you are about to force push history, please confirm (y/n)? " -n 1 -r;
echo
@@ -33,10 +40,10 @@ n=$#;
}
branch=${!n}
-[[ $branch = */* ]] && echo "Usage: push <?opts> <remote> <branch>" && exit 1
+[[ $branch = */* ]] && usage
let n--
-[[ $n -gt 0 && ${!n} != -* ]] && rmt=${!n} || { echo "Usage: push <?opts> <remote> <branch>" && exit 1; }
+[[ $n -gt 0 && ${!n} != -* ]] && rmt=${!n} || usage
to="$rmt/$branch"
remote=$("$GIT_EXE" g2getremote)
if [[ -z $remote ]]; then
View
14 cmds/g2-key.sh
@@ -1,16 +1,26 @@
#!/bin/bash
#
+source "$G2_HOME/cmds/color.sh"
+
+displayKey() {
+
+ echo -e -n "${yellowf}"
+ cat "$HOME/.ssh/id_rsa.pub"
+ echo -e -n "${reset}"
+
+}
+
gen() {
echo "Generating SSH keys..."
emailinput=$("$GIT_EXE" config --global --get user.email)
ssh-keygen -t rsa -P "" -C "$emailinput" -f "$HOME/.ssh/id_rsa"
- cat "$HOME/.ssh/id_rsa.pub"
+ displayKey
}
if [[ $1 != -gen ]]; then
- [[ ! -f $HOME/.ssh/id_rsa.pub ]] && echo "fatal: SSH key not found: $HOME/.ssh/id_rsa.pub" || cat "$HOME/.ssh/id_rsa.pub"
+ [[ ! -f $HOME/.ssh/id_rsa.pub ]] && echo_fatal "fatal: SSH key not found: $HOME/.ssh/id_rsa.pub" || displayKey
else
if [[ -f $HOME/.ssh/id_rsa.pub ]]; then
read -p "Regenerate SSH Key (y/n)? " -n 1 -r
View
12 cmds/g2-mg.sh
@@ -1,7 +1,9 @@
#!/bin/bash
#
-[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo "fatal: merging on a wip commit is forbiden, please <unwip> and commit <ci> first..." && exit 1
+source "$G2_HOME/cmds/color.sh"
+
+[[ $("$GIT_EXE" g2iswip) = "true" ]] && echo_fatal "fatal: merging on a wip commit is forbiden, please <unwip> and commit <ci> first..." && exit 1
# substitute "upstream" with real upstream name
declare -a v=("$@")
@@ -10,7 +12,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. <g track remote/branch>" && exit 1
+ [[ -z $remote ]] && echo_fatal "fatal: upstream not found, please setup tracking for this branch, ie. <g track remote/branch>" && exit 1
set -- "${@:1:$i}" "origin/master" "${@:($i+2)}";
} && break
let i++
@@ -23,9 +25,9 @@ done
unmerged=$("$GIT_EXE" ls-files --unmerged)
if [[ -n $unmerged ]]; then
- echo "info: some files need to be merged manually, please use <mt> to fix conflicts..."
- echo " once all resolved, <freeze> and <commit> the files."
- echo " note that you may <abort> at any time."
+ echo_info "info: some files need to be merged manually, please use <mt> to fix conflicts..."
+ echo_info " once all resolved, <freeze> and <commit> the files."
+ echo_info " note that you may <abort> at any time."
fi
exit 1;
}
View
21 cmds/g2-sync.sh
@@ -2,19 +2,22 @@
#
# Performs a fetch, rebase, push with a bunch of validations
#
+
+source "$G2_HOME/cmds/color.sh"
+
[[ $1 == "upstream" ]] && pullOnly=true && shift
-[[ $# -gt 0 ]] && echo "Usage: <sync>" && echo "Remember, <sync>hing applies to the working branch, when <pull>ing applies when merging feature branches" && exit 1
+[[ $# -gt 0 ]] && echo_fatal "Usage: <sync>" && echo_fatal "Remember, <sync>hing applies to the working branch, when <pull>ing applies when merging feature branches" && exit 1
remote=$("$GIT_EXE" g2getremote)
-[[ $("$GIT_EXE" g2iswip $remote) = "true" ]] && echo "fatal: sorry, wip commits shall not be synced. Please <unwip>, then <freeze> & commit <ci>" && exit 1;
-[[ -z $remote ]] && echo "fatal: please use <track> to setup the remote/branch to track with" && exit 2
-[[ $# -ne 0 ]] && echo "fatal: sorry, you may only <sync> against the tracking remote/branch, use <pull> or <push> to deal with other branches." && exit 3
+[[ $("$GIT_EXE" g2iswip $remote) = "true" ]] && echo_fatal "fatal: sorry, wip commits shall not be synced. Please <unwip>, then <freeze> & commit <ci>" && exit 1;
+[[ -z $remote ]] && echo_fatal "fatal: please use <track> to setup the remote/branch to track with" && exit 2
+[[ $# -ne 0 ]] && echo_fatal "fatal: sorry, you may only <sync> against the tracking remote/branch, use <pull> or <push> to deal with other branches." && exit 3
"$GIT_EXE" fetch || exit $?;
[[ $("$GIT_EXE" g2isforced $remote) = "true" ]] &&
- echo "abort: it appears the history of the branch was changed on the server." &&
- echo " please issue a <g rs upstream> or a <g rb $remote> to resume" &&
+ echo_fatal "abort: it appears the history of the branch was changed on the server." &&
+ echo_fatal " please issue a <g rs upstream> or a <g rb $remote> to resume" &&
exit 1;
branch=$("$GIT_EXE" branch | grep "*" | sed "s/* //")
"$GIT_EXE" rev-list --left-right $branch...$remote -- 2> /dev/null > /tmp/git_upstream_status_delta
@@ -23,9 +26,9 @@ rchg=$(grep -c "^>" /tmp/git_upstream_status_delta);
[[ $rchg -gt 0 ]] && { "$GIT_EXE" rebase $remote || {
unmerged=$("$GIT_EXE" ls-files --unmerged)
if [[ -n $unmerged ]]; then
- echo "info: some files need to be merged manually, please use <g mt> to fix conflicts."
- echo " Once all resolved, do NOT commit, but use <g continue> to resume."
- echo " Note that you may <abort> at any time"
+ echo_info "info: some files need to be merged manually, please use <g mt> to fix conflicts."
+ echo_info " Once all resolved, do NOT commit, but use <g continue> to resume."
+ echo_info " Note that you may <abort> at any time"
fi
exit 1;
}
View
9 g2-install.sh
@@ -15,8 +15,8 @@ export G2_HOME=$DIR
source ./cmds/color.sh
tips=(
-"${italicson}g sync${italicsoff} adds your changes to the tip of the branch and synchronizes with the servers both ways."
-"${italicson}g freeze${italicsoff} is a handy command to litteraly freeze the state of the repository."
+"${boldon}g sync${boldoff} adds your changes to the tip of the branch and synchronizes with the servers both ways."
+"${boldon}g freeze${boldoff} is a handy command to freeze all the changes in one shot."
"${boldon}g2${boldoff} saves time by providing high level commands."
"${boldon}g2${boldoff} is safer than git as it prompts before destructive actions."
"run ${boldon}g setup${boldoff} to configure git."
@@ -34,7 +34,8 @@ tips=(
"Need to display your ssh public key? try ${boldon}g key${boldoff}."
"${boldon}g2${boldoff} is just easier at undoing things: try ${boldon}g undo commit${boldoff} or ${boldon}g undo merge${boldoff}."
"When lost, ${boldon}g panic${boldoff} is the easiest way to get you back on track."
-);
+"Use ${boldon}g track${boldoff} to review how local/remote branches are setup."
+"Unlike git, ${boldon}g2${boldoff} actions only apply to the current branch.");
echo -n -e "Installing ${boldon}G2${boldoff}.."
@@ -51,7 +52,7 @@ alias git=__g2_eval;
echo " Enjoy!"
-echo -e "${boldon}Tip of the day${boldoff} : ${tips[RANDOM % ${#tips[@]}]} ${reset}"
+echo -e "${boldon}Tip of the day${boldoff}: ${tips[RANDOM % ${#tips[@]}]} ${reset}"
cd $OLDpwd
View
89 g2.sh
@@ -14,6 +14,8 @@ GIT_EXE=$(which git)
[[ -z "$GIT_EXE" ]] && echo "Sorry git not found in the PATH";
export GIT_EXE
+source "$G2_HOME/cmds/color.sh"
+
function __g2_contains() {
local n=$#
local value=${!n}
@@ -27,50 +29,49 @@ function __g2_contains() {
}
function __g2_usage() {
- cat << EOF
-Usage:
- abort - aborts any rebase/merge
- am <?-f> - amends last commit with staging area
- br <?-D> <?-M> <?branch> - list or create branches
- bs - bisect
- co <branch> - switches branch (either local/remote)
- continue - resumes a conflict resolution
- cp <commit> - cherry-pick
- ci <?params...> - commit
- clone <url> - clone a remote repository
- df/dt <?params...> <file> - compares files
- fetch - synchronizes remote branches
- freeze/unfreeze <?-m comment> <?file> - freeze/unfreeze files
- gc - garbage collects: run fsck & gc
- gp - grep
- gui - launches the GUI
- ig <file> - adds to gitignore & removes from source control
- init <folder> - init a repository
- key <?-gen> - displays/generates your ssh public key
- mg <?params...> <branch> - merge
- mt <?params...> - fixes conflicts by opening a visual mergetool
- mv - move (rename) a file
- lg - displays commit log
- ls <?params...> - list files under source control
- panic - gets you back on HEAD, cleans all untracked files
- pull/push <?opts> <remote> <branch> - deals with other branches
- rb <?params...> <branch> or <upstream> - rebase
- rm <params...> - remove
- rs <params...> - reset
- rs upstream - resets branch to upstream state
- rt <?params...> - remote
- rv <commit> - revert
- setup - configures user, key, editor, tools
- sh <?-deep> - show commit contents
- sm <?params...> - submodule
- ss <?params> - stash
- st <?params...> - status
- sync <?upstream> - syncs working branch: fetch, rebase & push
- tg - tag
- track <?upstream_branch> - shows/set tracking
- undo <file>|commit <hash>|merge - reverts changes
- wip/unwip - save/restore work in progress to branch
-EOF
+ echo -e "G2 Usage:
+ ${boldon}abort${boldoff} - aborts any rebase/merge
+ ${boldon}am <?-f>${boldoff} - amends last commit with staging area
+ ${boldon}br <?-D> <?-M> <?branch>${boldoff} - list or create branches
+ ${boldon}bs${boldoff} - bisect
+ ${boldon}co <branch>${boldoff} - switches branch (either local/remote)
+ ${boldon}continue${boldoff} - resumes a conflict resolution
+ ${boldon}cp <commit>${boldoff} - cherry-pick
+ ${boldon}ci <?params...>${boldoff} - commit
+ ${boldon}clone <url>${boldoff} - clone a remote repository
+ ${boldon}df/dt <?params...> <file>${boldoff} - compares files
+ ${boldon}fetch${boldoff} - gets changes sitting on the server
+ ${boldon}freeze/unfreeze <?-m comment> <?file>${boldoff} - freeze/unfreeze files
+ ${boldon}gc${boldoff} - garbage collects: run fsck & gc
+ ${boldon}gp${boldoff} - grep
+ ${boldon}gui${boldoff} - launches the GUI
+ ${boldon}ig <file>${boldoff} - adds to gitignore & removes from source control
+ ${boldon}init <folder>${boldoff} - init a repository
+ ${boldon}key <?-gen>${boldoff} - displays/generates your ssh public key
+ ${boldon}mg <?params...> <branch>${boldoff} - merge
+ ${boldon}mt <?params...>${boldoff} - fixes conflicts by opening a visual mergetool
+ ${boldon}mv${boldoff} - move (rename) a file
+ ${boldon}lg${boldoff} - displays commit log
+ ${boldon}ls <?params...>${boldoff} - list files under source control
+ ${boldon}panic${boldoff} - gets you back on HEAD, cleans all untracked files
+ ${boldon}pull/push <?opts> <remote> <branch>${boldoff} - deals with other branches
+ ${boldon}rb <?params...> <branch> or <upstream>${boldoff} - rebase
+ ${boldon}rm <params...>${boldoff} - remove files
+ ${boldon}rs <params...>${boldoff} - reset branch status
+ ${boldon}rs upstream${boldoff} - resets branch to upstream state
+ ${boldon}rt <?params...>${boldoff} - remote management
+ ${boldon}rv <commit>${boldoff} - reverts commits
+ ${boldon}setup${boldoff} - configures user, key, editor, tools
+ ${boldon}sh <?-deep>${boldoff} - show commit contents
+ ${boldon}sm <?params...>${boldoff} - submodule
+ ${boldon}ss <?params>${boldoff} - stash
+ ${boldon}st <?params...>${boldoff} - status
+ ${boldon}sync <?upstream>${boldoff} - syncs working branch: fetch, rebase & push
+ ${boldon}tg${boldoff} - tag
+ ${boldon}track <?upstream_branch>${boldoff} - shows/set tracking
+ ${boldon}undo <file>|commit <hash>|merge${boldoff} - reverts changes
+ ${boldon}wip/unwip${boldoff} - save/restore work in progress to branch"
+
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.