2018-03-04 19:04:57 GMT

git bash function gitnew update 2018-03-04

Previously on this topic: - [Git bash - Create remote repositories quickly on github and gitlab][1] - [git bash function gitnew version 20161021-2045, now with BitBucket][2] - [git bash function gitnew version 20161023-0057, with less redundancy][3] After migrating to my latest pc build (ryzen/vega), I realized my `gitnew` function wasn't working anymore. So here's the update: ```` gitnew() { # token path tokenPath='P:/' # name of the remote in the config remoteName='all' # remoteOrder # first is main, others are secondary # the values here are keys for remoteUrl and remoteUser remoteOrder=( 'github' 'gitlab' 'bitbucket' ) # remote urls (where to push) declare -A remoteUrl=( ['github']='git@github.com:spenibus' ['gitlab']='git@gitlab.com:spenibus' ['bitbucket']='git@bitbucket.org:spenibus' ) # remote users (who is pushing) declare -A remoteUser=( ['github']='spenibus' ['gitlab']='spenibus' ['bitbucket']='spenibus' ) ##### no config edits below this point # token folder does not exist if [ ! -d "$tokenPath" ]; then echo 'error: token folder not available' # .git subfolder does not exist elif [ ! -d ".git" ]; then echo 'error: .git folder is missing' # we got everything we need else # repo name repoName="$(basename "$PWD")" for i in "${!remoteOrder[@]}" do # get key key=${remoteOrder[$i]} # build full url urlFull="${remoteUrl[$key]}"'/'"$repoName"'.git' echo 'Adding remote url' echo " $key" echo " $urlFull" # add main url if [ "$i" = "0" ]; then echo ' [main]' git remote add "$remoteName" "$urlFull" # add secondary url else echo ' [secondary]' # avoid duplicate git remote set-url "$remoteName" --delete "$urlFull" # add git remote set-url "$remoteName" --add "$urlFull" fi done echo $'\nQuerying github\n--------------------' curl \ -H 'Authorization: token '"$(cat "$tokenPath"'github.token.txt')"\ -d '{"name":"'"$repoName"'"}' \ 'https://api.github.com/user/repos' echo $'\nQuerying gitlab\n--------------------' curl \ -H 'Private-Token: '"$(cat "$tokenPath"'gitlab.token.txt')" \ --data-urlencode 'name='"$repoName" \ --data-urlencode 'public=true' \ 'https://gitlab.com/api/v3/projects' echo $'\nQuerying bitbucket\n--------------------' curl \ -X POST \ -H 'Content-Type: application/json' \ -u "${remoteUser[bitbucket]}":"$(cat "$tokenPath"'bitbucket.token.txt')" \ -d '{"scm":"git", "has_issues":true, "has_wiki":true}' \ 'https://api.bitbucket.org/2.0/repositories/'"${remoteUser[bitbucket]}"'/'"$repoName" fi } >&2 # http://stackoverflow.com/a/31656923/3512867 # http://stackoverflow.com/a/1500592/3512867 export -f gitnew ```` End of transmission. [1]: http://spenibus.net/b/p/r/Git-bash-Create-remote-repositories-quickly-on-github-and-gitlab [2]: http://spenibus.net/b/p/A/git-bash-function-gitnew-version-20161021-2045-now-with-BitBucket [3]: http://spenibus.net/b/p/B/git-bash-function-gitnew-version-20161023-0057-with-less-redundancy