Last active
March 17, 2019 03:33
-
-
Save masawada/bb9d6e4432a1dae7c4bab2c3f1a3cc34 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 | |
# LICENSE: MIT | |
SERVICE_NAME="github.com" | |
USER_NAME=$USER | |
usage_exit() { | |
echo "Usage: git new-repo [-u user] [-s service] repo_name" 1>&2 | |
exit 1 | |
} | |
while getopts u:s:h OPT | |
do | |
case $OPT in | |
u) USER_NAME=$OPTARG ;; | |
s) SERVICE_NAME=$OPTARG ;; | |
h) usage_exit ;; | |
\?) usage_exit ;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
REPO_NAME=$1 | |
[[ $REPO_NAME = '' ]] && usage_exit | |
set -eu | |
GHQ_ROOT=$(git config --get-all ghq.root | peco | sed "s|~|$HOME|") | |
REPO_PATH="$GHQ_ROOT/${SERVICE_NAME}/${USER_NAME}/${REPO_NAME}" | |
if [ -e ${REPO_PATH} ]; then | |
echo "repository already exists" | |
exit 1; | |
fi | |
mkdir -p ${REPO_PATH} | |
cd ${REPO_PATH} | |
git init | |
touch README.md | |
ghq look ${SERVICE_NAME}/${USER_NAME}/${REPO_NAME} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment