Last active
August 29, 2015 13:58
-
-
Save farfanoide/10146013 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
#!/usr/bin/env bash | |
# ------------------------------------------------------------------------------ | |
# Description | |
# ----------- | |
# | |
# Script to create a github repo and [if possible] add it as a remote | |
# on the current one | |
# | |
# ------------------------------------------------------------------------------ | |
# Author | |
# ------- | |
# | |
# * Farfanoide (https://github.com/farfanoide) | |
# | |
# ------------------------------------------------------------------------------ | |
[ $# -eq 0 ] && echo "Usage: $(basename $0) <repository_name> [username]" && exit 1 | |
repo_name=$1; shift | |
[ $# -gt 0 ] && username=$1 || username=$(git config github.user) | |
endpoint='https://api.github.com/user/repos' | |
repo_url="$(curl -u ${username} ${endpoint} -d "{\"name\":\"${repo_name}\"}" | grep ssh_url | cut -d\" -f4 )" | |
origin="$(git remote -v | grep origin)" | |
if [ ! -z "${repo_url}" -a -z "${origin}" ]; then | |
git remote add origin $repo_url | |
fi | |
# TODO: git init if not exists, ask for remote name if origin exists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment