Skip to content

Instantly share code, notes, and snippets.

@Giemsa
Created September 9, 2014 13:13
Show Gist options
  • Save Giemsa/c6f3851127ef1293c1f6 to your computer and use it in GitHub Desktop.
Save Giemsa/c6f3851127ef1293c1f6 to your computer and use it in GitHub Desktop.
ブランチ切り替えまくるのに疲弊したあなたに捧ぐシェルスクリプト
#!/bin/sh
# git-new-workdirのパス
GIT_WD_PATH=/usr/local/share/git-core/contrib/workdir/git-new-workdir
BRANCH_NAME=
WORKDIR_NAME=
REMOTE_URL=`git config --get remote.origin.url`
case $# in
0)
BRANCH_NAME=`git rev-parse --abbrev-ref HEAD`
WORKDIR_NAME=`git config --get wd.workspace`
;;
1)
BRANCH_NAME=$1
WORKDIR_NAME=`git config --get wd.workspace`
;;
2)
BRANCH_NAME=$1
WORKDIR_NAME=$2
;;
*)
echo "Usage: git cwd [ BRANCH_NAME ] [ WORKDIR_PATH ]"
exit 0
;;
esac
if [ -z "$WORKDIR_NAME" ] ; then
echo "working directory is must be specified." 1>&2
exit 1
fi
found=0
for branch in `git for-each-ref refs/heads/ --format='%(refname:short)'`; do
if [[ "$branch" == "$BRANCH_NAME" ]]; then
found=1
break
fi
done
if [ $found -eq 0 ] ; then
echo "branch $BRANCH_NAME not found" 1>&2
exit 1
fi
REMOTE_URL=${REMOTE_URL##*/}
$GIT_WD_PATH . $WORKDIR_NAME/${REMOTE_URL%.*}/$BRANCH_NAME $BRANCH_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment