Created
April 20, 2017 12:01
-
-
Save hkdsun/519673464a5f5cc4eec598684f8f54f1 to your computer and use it in GitHub Desktop.
Create and push Bitbucket repository from your terminal
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 | |
function ask() { | |
while true; do | |
if [ "${2:-}" = "Y" ]; then | |
prompt="Y/n" | |
default=Y | |
elif [ "${2:-}" = "N" ]; then | |
prompt="y/N" | |
default=N | |
else | |
prompt="y/n" | |
default= | |
fi | |
read -p "$1 [$prompt] " REPLY </dev/tty | |
if [ -z "$REPLY" ]; then | |
REPLY=$default | |
fi | |
case "$REPLY" in | |
Y*|y*) return 0 ;; | |
N*|n*) return 1 ;; | |
esac | |
done | |
} | |
function bitgit() { | |
(git status 2>&1) >/dev/null | |
if [[ "$?" != "0" ]]; then | |
echo "Not a git repo" | |
return | |
fi | |
read -p "Username: " username | |
read -s -p "Password: " pass | |
echo | |
name=$(basename `pwd`) | |
read -p "Repo Name [$name]: " name_i | |
if [[ -n "$name_i" ]]; then | |
name="$name_i" | |
fi | |
private="" | |
if ask "Private?" Y; then | |
private="true" | |
else | |
private="false" | |
fi | |
curl --progress-bar --user "$username:$pass" | |
https://api.bitbucket.org/1.0/repositories/ --data name="$name" --data is_private="$private" | jq .resource_uri | |
echo | |
if ask "Push repo?" Y; then | |
git remote add origin "git@bitbucket.org:/$username/$name" | |
git push -u origin master | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Depends on
jq
for niceties. You can remove the| jq .resource_uri
if you don't like that