Skip to content

Instantly share code, notes, and snippets.

@fprochazka
Created October 23, 2010 12:55
Show Gist options
  • Save fprochazka/642174 to your computer and use it in GitHub Desktop.
Save fprochazka/642174 to your computer and use it in GitHub Desktop.
funky git controller (sample: http://i55.tinypic.com/ao0038.jpg)
#!/bin/bash
srcLibs="/var/www"
black='\e[0;30m' # Black - Regular
red='\e[0;31m' # Red
green='\e[0;32m' # Green
yellow='\e[0;33m' # Yellow
blue='\e[0;34m' # Blue
purple='\e[0;35m' # Purple
cyan='\e[0;36m' # Cyan
white='\e[0;37m' # White
Bblack='\e[1;30m' # Black - Bold
Bred='\e[1;31m' # Red
Bgreen='\e[1;32m' # Green
Byellow='\e[1;33m' # Yellow
Bblue='\e[1;34m' # Blue
Bpurple='\e[1;35m' # Purple
Bcyan='\e[1;36m' # Cyan
Bwhite='\e[1;37m' # White
colored() {
# colored $green "text"
echo -e "$1$2\033[0m"
}
colored_oneline() {
# colored $green "text"
echo -en "$1$2\033[0m"
}
git_run() {
gitCommand=""
title="git $ "
if [ "$gitRepo" != "" ] ; then
title="$gitRepo@$title"
fi;
while true ; do
colored_oneline $Bwhite "$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"
git config --global core.autocrlf "false"
# rebase
# git config branch.autosetuprebase always
git config --global branch.autosetuprebase "always"
# aliases
git config --global alias.l "log --oneline --graph"
git config --global alias.st "status"
git config --global alias.co "checkout"
git config --global alias.b "branch"
# colors
git config --global color.ui always
# [color]
# branch = auto
# diff = auto
# status = auto
# [color "branch"]
# current = yellow reverse
# local = yellow
# remote = green
# [color "diff"]
# meta = yellow bold
# frag = magenta bold
# old = red bold
# new = green bold
# [color "status"]
# added = yellow
# changed = green
# untracked = cyan
}
is_in_repo() {
[ -d .git ]
}
get_list_repo_folders() {
tmp=$(mktemp)
find -L "$srcLibs" -name '*.git' | sort > $tmp
}
list_repos() {
#comm -12 <(<tmp sed -n 's!/\.git$!!p' | sort)
colored $Bgreen "choose repository (by name or index):"
echo
c=1
for l in $(cat $tmp) ; do
name=`echo "$l"|sed "s@^$srcLibs/@@"|sed "s@/.git@@"`
colored $Bblue " $c $name"
c=$(( $c + 1 ))
done
}
clear_list_repo_folders() {
rm "$tmp" &>/dev/null
}
choose_repo() {
echo
colored_oneline $Bwhite "repository: "
read gitRepo
cd "$srcLibs/$gitRepo" &>/dev/null
}
choose_repo_index() {
c=1
for l in $(cat $tmp) ; 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 $Bred "repository '$gitRepo' not found!"
echo
list_repos
fi;
else
colored $Bred "repository '$gitRepo' not found!"
echo
list_repos
fi;
done
colored $Bgreen "switched to repository $gitRepo"
clear_list_repo_folders
git status
echo
colored $Bwhite "(type 'q' for repository list or hit Enter for git help)"
echo
git_run
fi;
}
git_configure
main_control
@fprochazka
Copy link
Author

$ ./git-control.sh

Pokud není umístěn v repozitáři nabídne seznam složek které jsou repozitář ve složce definované v "srcLibs" na začátku scriptu.

Po vybrání repozitáře simuluje "konzoli gitu".

@fprochazka
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment