tj.git-extras/bin/git-gh-oauth

18 lines
578 B
Bash

#!/bin/sh
user=`git config github.user`
test -z "$user" && echo "failed to fetch github.user" 1>&2 && exit 1
oauthToken=`git config github.oauthToken`
if [ -z $oauthToken ] ; then
echo "Github oAuth token not found. Creating a new one."
stty_orig=`stty -g`
stty -echo
printf "Github password:"
read passwd
stty $stty_orig
url="https://api.github.com/authorizations"
oauthToken=$(curl -# -u "$user:$passwd" $url -d '{"scopes": ["repo", "user", "gist"]}' | jshon -e token | sed -e 's/"//g')
git config --global github.oauthToken $oauthToken
fi
echo $oauthToken