diff options
| author | typebrook <typebrook@gmail.com> | 2020-01-22 13:26:28 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-01-22 13:26:28 +0800 |
| commit | f22363e9a4cc0ace864cd39dcf26f6370cec1d38 (patch) | |
| tree | 4fb8a5af5560217e649cd00af5a85983d1a43dd1 | |
| parent | bbfadc2751bf756747079cde467b6b65cfb7d606 (diff) | |
update
| -rwxr-xr-x | scripts/gist | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/scripts/gist b/scripts/gist index 4682255..bcb6541 100755 --- a/scripts/gist +++ b/scripts/gist | |||
| @@ -74,15 +74,15 @@ _auth() { | |||
| 74 | --user "$user:$password" -H "X-GitHub-OTP: $OTP" \ | 74 | --user "$user:$password" -H "X-GitHub-OTP: $OTP" \ |
| 75 | --data "$data" |\ | 75 | --data "$data" |\ |
| 76 | sed '1 s/[^{]//g' | jq -r .token |\ | 76 | sed '1 s/[^{]//g' | jq -r .token |\ |
| 77 | sed 's/^/github_api_token=/' >> $config | 77 | sed 's/^/token=/' >> $config |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | while ! source $config &> /dev/null || [[ -z "$user" ]] || [[ -z "$github_api_token" ]]; do | 80 | while ! source $config; do |
| 81 | _auth | 81 | _auth |
| 82 | done | 82 | done |
| 83 | 83 | ||
| 84 | github_api=https://api.github.com | 84 | github_api=https://api.github.com |
| 85 | auth_header="Authorization: token $github_api_token" | 85 | auth_header="Authorization: token $token" |
| 86 | 86 | ||
| 87 | [[ -z "$folder" ]] && folder=~/git/gist | 87 | [[ -z "$folder" ]] && folder=~/git/gist |
| 88 | mkdir -p $folder | 88 | mkdir -p $folder |
| @@ -275,22 +275,30 @@ _help_message() { | |||
| 275 | sed -E -n ' /^$/ q; 8,$ s/^#//p' $0 | 275 | sed -E -n ' /^$/ q; 8,$ s/^#//p' $0 |
| 276 | } | 276 | } |
| 277 | 277 | ||
| 278 | # TODO consider the case that $2 is empty -> remove original setting | 278 | _cases() { |
| 279 | _configure() { | ||
| 280 | [[ -z "$@" ]] && vim $config && exit 0 &> /dev/null ||\ | ||
| 281 | echo edit file $config directly && exit 0 | ||
| 282 | |||
| 283 | case "$1 $2" in | 279 | case "$1 $2" in |
| 284 | token) echo github_api_token=$2 ;; | 280 | token[[:space:]]*) |
| 285 | auto_sync[[:space:]]false) echo $1=$2 ;; | 281 | [[ ${#2} -eq 40 ]] && echo token=$2 ||\ |
| 282 | echo Invalid token format, it is not 40 chars > /dev/tty;; | ||
| 283 | auto_sync[[:space:]]*) ;& | ||
| 284 | *false$) echo $1=$2 ;; | ||
| 285 | *) ;; | ||
| 286 | folder[[:space:]]*) echo $1=$2 ;; | 286 | folder[[:space:]]*) echo $1=$2 ;; |
| 287 | *) echo Not well formated; exit 0;; | 287 | user[[:space:]]*) echo $1=$2 ;; |
| 288 | esac >> $config | 288 | *) echo Not well formated > /dev/tty;; |
| 289 | sed -i "$ q; /^$1=/ d" $config | 289 | esac |
| 290 | } | ||
| 290 | 291 | ||
| 292 | # TODO consider the case that $2 is empty -> remove original setting | ||
| 293 | _configure() { | ||
| 294 | [[ -z "$@" ]] && (vim $config) && exit 0 | ||
| 295 | target=$(_cases "$@") | ||
| 296 | |||
| 297 | [[ -n $target ]] && sed -i "/^$1=/ d" $config && echo $target >> $config | ||
| 291 | cat $config | 298 | cat $config |
| 292 | } | 299 | } |
| 293 | 300 | ||
| 301 | |||
| 294 | case "$1" in | 302 | case "$1" in |
| 295 | "") | 303 | "") |
| 296 | _show_list $index ;; | 304 | _show_list $index ;; |