From f22363e9a4cc0ace864cd39dcf26f6370cec1d38 Mon Sep 17 00:00:00 2001 From: typebrook Date: Wed, 22 Jan 2020 13:26:28 +0800 Subject: update --- scripts/gist | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'scripts/gist') diff --git a/scripts/gist b/scripts/gist index 4682255..bcb6541 100755 --- a/scripts/gist +++ b/scripts/gist @@ -74,15 +74,15 @@ _auth() { --user "$user:$password" -H "X-GitHub-OTP: $OTP" \ --data "$data" |\ sed '1 s/[^{]//g' | jq -r .token |\ - sed 's/^/github_api_token=/' >> $config + sed 's/^/token=/' >> $config } -while ! source $config &> /dev/null || [[ -z "$user" ]] || [[ -z "$github_api_token" ]]; do +while ! source $config; do _auth done github_api=https://api.github.com -auth_header="Authorization: token $github_api_token" +auth_header="Authorization: token $token" [[ -z "$folder" ]] && folder=~/git/gist mkdir -p $folder @@ -275,22 +275,30 @@ _help_message() { sed -E -n ' /^$/ q; 8,$ s/^#//p' $0 } -# TODO consider the case that $2 is empty -> remove original setting -_configure() { - [[ -z "$@" ]] && vim $config && exit 0 &> /dev/null ||\ - echo edit file $config directly && exit 0 - +_cases() { case "$1 $2" in - token) echo github_api_token=$2 ;; - auto_sync[[:space:]]false) echo $1=$2 ;; + token[[:space:]]*) + [[ ${#2} -eq 40 ]] && echo token=$2 ||\ + echo Invalid token format, it is not 40 chars > /dev/tty;; + auto_sync[[:space:]]*) ;& + *false$) echo $1=$2 ;; + *) ;; folder[[:space:]]*) echo $1=$2 ;; - *) echo Not well formated; exit 0;; - esac >> $config - sed -i "$ q; /^$1=/ d" $config + user[[:space:]]*) echo $1=$2 ;; + *) echo Not well formated > /dev/tty;; + esac +} +# TODO consider the case that $2 is empty -> remove original setting +_configure() { + [[ -z "$@" ]] && (vim $config) && exit 0 + target=$(_cases "$@") + + [[ -n $target ]] && sed -i "/^$1=/ d" $config && echo $target >> $config cat $config } + case "$1" in "") _show_list $index ;; -- cgit v1.2.3-70-g09d2