Skip to content

Instantly share code, notes, and snippets.

@Mikulas
Forked from fprochazka/git-control.sh
Created October 23, 2010 18:42
Show Gist options
  • Save Mikulas/642544 to your computer and use it in GitHub Desktop.
Save Mikulas/642544 to your computer and use it in GitHub Desktop.
Git project control for Mac
#!/bin/bash
srcLibs="/Volumes/Data/Web"
colorPrefix="\033["
colorPostfix="\033[0m"
color_default="0"
color_red="31"
color_red_bold="1;31"
color_green="32"
color_green_bold="1;32"
color_blue="34"
color_blue_bold="1;34"
colored() {
# colored $color "text"
echo -e $colorPrefix $1 "m" $2 $colorPostfix
}
colored_oneline() {
# colored $effect $foreground $background "text"
echo -en $colorPrefix $1 "m" $2 $colorPostfix
}
git_run() {
gitCommand=""
title="git $ "
if [ "$gitRepo" != "" ] ; then
title="$gitRepo@$title"
fi;
while true ; do
colored_oneline $color_default "$title"
read gitCommand
if [ -z "$gitCommand" ] ; then
gitCommand=" --help"
elif [ "$gitCommand" = "q" ] ; then
gitRepo=""
cd $srcLibs
main_control
return 1
fi;
git $gitCommand ;
echo
gitCommand=""
done
}
git_configure() {
# endlines
# git config core.autocrlf "false" &>/dev/null
git config --global core.autocrlf "false" &>/dev/null
# rebase
# git config branch.autosetuprebase always &>/dev/null
git config --global branch.autosetuprebase "always" &>/dev/null
# aliases
git config --global alias.l "log --oneline --graph" &>/dev/null
git config --global alias.st "status" &>/dev/null
git config --global alias.co "checkout" &>/dev/null
git config --global alias.b "branch" &>/dev/null
# colors
git config --global color.ui always &>/dev/null
}
is_in_repo() {
[ -d .git ]
}
get_list_repo_folders() {
repos=`find -L "$srcLibs" -name '*.git' 2>/dev/null | sort`
}
list_repos() {
#comm -12 <(<tmp sed -n 's!/\.git$!!p' | sort)
colored $color_green "choose repository (by name or index):"
c=1
for l in $repos ; do
name=`echo "$l"|sed "s@^$srcLibs/@@"|sed "s@/.git@@"`
colored_oneline $color_blue "\t$c"
colored $color_default "$name"
c=$(( $c + 1 ))
done
}
choose_repo() {
echo
colored_oneline $color_green "repository: "
read gitRepo
cd "$srcLibs/$gitRepo" &>/dev/null
}
choose_repo_index() {
c=1
for l in $repos ; do
name=`echo "$l"|sed "s@^$srcLibs/@@"|sed "s@/.git@@"`
if [ $c -eq $1 ] ; then
cd "$srcLibs/$name" &>/dev/null
gitRepo="$name"
fi
c=$(( $c + 1 ))
done
}
main_control () {
gitRepo=""
if is_in_repo ; then
git_run
else
get_list_repo_folders
list_repos
while true; do
gitRepo=""
choose_repo ;
if is_in_repo ; then
break;
elif [ "$gitRepo" -ge 0 &>/dev/null ]; then
choose_repo_index $gitRepo ;
if is_in_repo ; then
break;
else
colored $color_red_bold "repository '$gitRepo' not found!"
echo
list_repos
fi;
else
colored $color_red_bold "repository '$gitRepo' not found!"
echo
list_repos
fi;
done
colored $color_red_bold "switched to repository $gitRepo"
git status
echo
colored $color_red_bold "(type 'q' for repository list or hit Enter for git help)"
echo
git_run
fi;
}
git_configure
main_control
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment