summaryrefslogtreecommitdiffhomepage
path: root/scripts/gist
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gist')
-rwxr-xr-xscripts/gist34
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
80while ! source $config &> /dev/null || [[ -z "$user" ]] || [[ -z "$github_api_token" ]]; do 80while ! source $config; do
81 _auth 81 _auth
82done 82done
83 83
84github_api=https://api.github.com 84github_api=https://api.github.com
85auth_header="Authorization: token $github_api_token" 85auth_header="Authorization: token $token"
86 86
87[[ -z "$folder" ]] && folder=~/git/gist 87[[ -z "$folder" ]] && folder=~/git/gist
88mkdir -p $folder 88mkdir -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
294case "$1" in 302case "$1" in
295 "") 303 "")
296 _show_list $index ;; 304 _show_list $index ;;