Last active
May 30, 2017 21:49
-
-
Save antonioribeiro/9e014ad6a27d98d8dd0a57aa7883144f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# The path where you usually put your repositories on | |
export MKREPO_REPOSITORIES_BASE_PATH=~/code/ | |
# The path where your initial files (README.md, LICENSE.md and .gitingore) are | |
export MKREPO_SKELETON_PATH=/Users/antoniocarlos/Dropbox/development/.skeleton/ | |
function mkrepo { | |
#/ | |
## Splash | |
#/ | |
echo "mkrepo 0.1.0" | |
echo "Base repositories path: $MKREPO_REPOSITORIES_BASE_PATH" | |
echo "Init files path: $MKREPO_SKELETON_PATH" | |
echo | |
#/ | |
## Check if hub is installed | |
#/ | |
if ! type hub &> /dev/null ; then | |
echo Looks like Hub is not installed, please install it and try again. | |
echo "If you are using a macOS, you can probably just run 'brew install hub'" | |
return; | |
fi | |
#/ | |
## Init vars | |
#/ | |
VISIBILITY=${1:---public} | |
NAME=${2:-_empty_} | |
SUBFOLDER=${3:-_empty_} | |
#/ | |
## Show help | |
#/ | |
if [ "$VISIBILITY" = "--help" ] || [ "$VISIBILITY" = "-help" ] || [ "$VISIBILITY" = "help" ]; then | |
echo "usage: mkrepo [--private or --public or --help] [repository name] [subfolder] " | |
echo | |
echo "** If you pass more than one argument, all previous arguments become mandatory" | |
echo | |
return; | |
fi | |
#/ | |
## Get the repository name | |
#/ | |
if [ "$NAME" = "_empty_" ]; then | |
printf "GitHub repository name: " | |
read NAME | |
fi | |
#/ | |
## Get the folder name | |
#/ | |
if [ "$SUBFOLDER" = "_empty_" ]; then | |
printf "Local folder: $MKREPO_REPOSITORIES_BASE_PATH" | |
read SUBFOLDER | |
fi | |
#/ | |
## Create and enters the folder | |
#/ | |
cd $MKREPO_REPOSITORIES_BASE_PATH | |
mkdir -p "$SUBFOLDER" | |
cd "$SUBFOLDER" | |
#/ | |
## Copy init files to repository | |
#/ | |
cp -a $MKREPO_SKELETON_PATH $MKREPO_REPOSITORIES_BASE_PATH/$SUBFOLDER | |
#/ | |
## Initialize Git repository | |
#/ | |
git init | |
#/ | |
## Create the repository on GitHub | |
#/ | |
if [ "$VISIBILITY" = "--private" ]; then | |
hub create $NAME -p | |
else | |
hub create $NAME | |
fi | |
#/ | |
## Add all files and push to master on GitHub | |
#/ | |
git add -A . | |
git commit -m "First commit." | |
git push -u origin master | |
#/ | |
## Show the repository on your default browser | |
#/ | |
hub browse | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment