Skip to content

Instantly share code, notes, and snippets.

@claudioc
Created June 29, 2012 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudioc/3016642 to your computer and use it in GitHub Desktop.
Save claudioc/3016642 to your computer and use it in GitHub Desktop.
#!/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