Created
February 27, 2016 09:50
-
-
Save akaishi-skiyaki/8f1cfe3a9c3e1eb8ead4 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 | |
GIT_CMD="" | |
CURRENT_BRANCH="" | |
FORCE=false | |
# メニュー表示時の文言。 | |
PS3="ブランチを選択してください > " | |
if [ "${1}" == "" ] ; then | |
echo "引数が指定されていません" | |
exit 1 | |
fi | |
case ${1} in | |
checkout ) | |
GIT_CMD="checkout" | |
;; | |
diff ) | |
GIT_CMD="diff" | |
;; | |
pull ) | |
GIT_CMD="pull" | |
;; | |
push ) | |
GIT_CMD="push" | |
;; | |
* ) | |
echo 'Invaild command' | |
exit 1 | |
;; | |
esac | |
if [ "${2}" == "-f" ]; then | |
FORCE=true | |
fi | |
# 選択されたブランチ名を確認する | |
# confirm -f | |
# -f FORCE 確認せずコマンドを実行する | |
confirm(){ | |
cmd="git ${GIT_CMD} ${CURRENT_BRANCH}" | |
if [ "${FORCE}" == "true" ]; then | |
${cmd} | |
exit 0 | |
fi | |
echo "${CURRENT_BRANCH} でよろしいですか? [Y/n]" | |
read ANSWER | |
case `echo ${ANSWER} | tr y Y` in | |
"" | Y* ) ${cmd} | |
exit 0;; | |
*) main;; | |
esac | |
} | |
# ブランチ名を一覧表示して選択する | |
# | |
main(){ | |
select item in `getBranches` | |
do | |
if [ "${REPLY}" = "q" ]; then | |
echo "選択を終了しました" | |
exit 0 | |
fi | |
if [ -z "${item}" ] ; then | |
continue | |
fi | |
case "${item}" in | |
quit ) echo "選択を終了しました" | |
exit 0 | |
;; | |
* ) | |
CURRENT_BRANCH=${item} | |
confirm -f | |
;; | |
esac | |
done | |
} | |
# ブランチ名を取得する 引数に false を渡すと quit を除外する | |
getBranches(){ | |
branches=$(git for-each-ref --format='%(refname:short)' --sort=-committerdate refs/heads) | |
# TODO 引数チェックをして追加をする | |
branches=${branches}" quit" | |
echo ${branches} | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment