Created
June 29, 2012 08:23
-
-
Save claudioc/3016642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MY_S=( ) | |
main() { | |
local current | |
local branch=${1} | |
local branches | |
local idx=0 | |
local quick | |
if [ "$(git rev-parse --git-dir 2>/dev/null)" = "" ]; then | |
echo "Not a git repository" | |
exit 1 | |
fi | |
if [ "${branch}" = "" ]; then | |
echo -e "\nPlease specify a branch (showing latest):\n" | |
#echo -e $(echo ${MY_S[@]:0} | sed 's/ /\\n/g') | |
while [ ${idx} -lt ${#MY_S[@]} ]; do | |
echo ${idx}. ${MY_S[${idx}]} | |
((idx++)) | |
done | |
exit 1 | |
fi | |
current=$(git symbolic-ref HEAD | sed 's/refs\/heads\///') | |
if [[ "${branch}" =~ ^[0-9]$ ]]; then | |
branch=${MY_S[${branch}]} | |
if [ "${branch}" = "" ]; then | |
echo "What!?" | |
exit 1 | |
fi | |
fi | |
if [ "${current}" = "${branch}" ]; then | |
echo "You already are on ${branch}" | |
exit 1 | |
fi | |
git checkout ${branch} | |
if [ $? -eq 0 ]; then | |
if [ "${branch}" = "-" ]; then | |
exit 0 | |
fi | |
if [ ${#MY_S[@]} -eq 5 ]; then | |
unset MY_S[0] | |
fi | |
MY_S[${#MY_S[@]}+1]=${branch} | |
branches=${MY_S[@]:0} | |
$(sed -i "s/^MY_S=\(.*\)/MY_S=( ${branches} )/g" ${0}) | |
fi | |
} | |
main $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment