From 9aa7980cb97d6ec13b86d670386ac70c05e5358b Mon Sep 17 00:00:00 2001 From: typebrook Date: Tue, 28 Jan 2020 09:57:12 +0800 Subject: update --- scripts/gist | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'scripts/gist') diff --git a/scripts/gist b/scripts/gist index bea6642..fe839a3 100755 --- a/scripts/gist +++ b/scripts/gist @@ -63,13 +63,27 @@ set -eo pipefail [ "$TRACE" ] && set -x _auth() { + echo 'Hi fellow! To access your gists, I need your Github username and a personal token with scope which allows "gist"!' read -p "Github username: " user < /dev/tty - mkdir -p ~/.config && umask 0077 && echo user=$user > $config - echo "Create a new token from web browser" - python -mwebbrowser https://github.com/settings/tokens/new\?scopes\=gist + if [[ $new_token =~ ^[[:alnum:]]+$ ]]; then + mkdir -p ~/.config + umask 0077 + echo user=$user > $config + else + echo "Not a valid username" + return 0 + fi + + echo -n "Create a new token from web browser? [Y/n] " + read answer < /dev/tty + if [[ ! $answer =~ ^(N|n|No|NO|no)$ ]]; then + python -mwebbrowser https://github.com/settings/tokens/new\?scopes\=gist; + fi read -p "Paste your token here: " new_token < /dev/tty - echo token=$new_token >> $config + [[ $new_token =~ ^[[:alnum:]]{40}$ ]] \ + && echo token=$new_token >> $config \ + || echo "Not a valid token" } case "$1" in -- cgit v1.2.3-70-g09d2