Last active
August 24, 2018 10:39
-
-
Save lajlev/0c5090cff87c36d34b9c4e940ac7b1d2 to your computer and use it in GitHub Desktop.
View, create & delete bitbucket repo via Bash function
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
# Create a Bitbucket repo | |
function bbcreate () { | |
if [ $# == 1 ]; then # Passing an parameter? | |
curl -s -S -X POST --user $BITBUCKET_USER:$BITBUCKET_PASS "https://api.bitbucket.org/2.0/repositories/lajlev/$1" -d "is_private=true" # Create a private repo | |
git init # Init local git repo | |
git remote add origin [email protected]:$BITBUCKET_USER/$1.git # Add Bitbucket repo as git remote | |
printf "\n\n\n π https://bitbucket.org/$BITBUCKET_USER/$1 created\n\n" # Confirm messsage | |
else # No parameter | |
printf "\n Please enter a repo name π\n\n" | |
fi | |
} | |
# Delete a Bitbucket repo | |
function bbdelete () { | |
if [ $# == 1 ]; then | |
read -r -p "Delete $1? [Y/n]" response # Confirm delete | |
response=${response,,} # lower letters in response | |
if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then # If confirmed | |
curl -s -S -X DELETE -u $BITBUCKET_USER:$BITBUCKET_PASS https://api.bitbucket.org/2.0/repositories/$BITBUCKET_USER/$1 # Delete repo on bitbucket | |
printf "\n π $1 deleted\n\n" # Confirm messsage | |
fi | |
else | |
printf "\n Please enter a repo name π\n\n" | |
fi | |
} | |
# Open repo on bitbucket.com in your default browser | |
function bitbucket() { | |
giturl=$(git config --get remote.origin.url) | |
if [ "$giturl" == "" ] | |
then | |
echo "Not a git repository or no remote.origin.url set" | |
fi | |
giturl=${giturl/git\@bitbucket\.org\:/https://bitbucket.org/} | |
giturl=${giturl/\.git/\/src} | |
giturl=${giturl/git@/http://} | |
open $giturl | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment