Skip to content

Instantly share code, notes, and snippets.

@lajlev
Last active August 24, 2018 10:39
Show Gist options
  • Save lajlev/0c5090cff87c36d34b9c4e940ac7b1d2 to your computer and use it in GitHub Desktop.
Save lajlev/0c5090cff87c36d34b9c4e940ac7b1d2 to your computer and use it in GitHub Desktop.
View, create & delete bitbucket repo via Bash function
# 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 git@bitbucket.org:$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