diff options
author | typebrook <typebrook@gmail.com> | 2020-02-01 12:27:07 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-02-01 12:27:07 +0800 |
commit | 90029eb46526841c7a1b9a8d43030211bb70d8ea (patch) | |
tree | ff904cb03b84022a29e987183765356e7abf0785 | |
parent | 0bc60cc2cc2225b6b17ebc07fb814d5fd3e5aef1 (diff) |
update
-rwxr-xr-x | scripts/gist | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/scripts/gist b/scripts/gist index b2767b1..ee400fb 100755 --- a/scripts/gist +++ b/scripts/gist | |||
@@ -42,7 +42,7 @@ | |||
42 | # It is your business to do git commit and git push | 42 | # It is your business to do git commit and git push |
43 | # | 43 | # |
44 | # * configuration | 44 | # * configuration |
45 | # gist (config | c) [token <value>] [user <value>] [folder <value>] [auto-sync false] | 45 | # gist (config | c) [token|user|folder|auto-sync|EDITOR|action [value]] |
46 | # | 46 | # |
47 | # * show this help message | 47 | # * show this help message |
48 | # gist (help | h) | 48 | # gist (help | h) |
@@ -111,8 +111,7 @@ _ask_token() { | |||
111 | _configure token $token | 111 | _configure token $token |
112 | } | 112 | } |
113 | 113 | ||
114 | # load configuration | 114 | _validate_config(){ |
115 | _apply_config() { | ||
116 | source $CONFIG 2> /dev/null || true | 115 | source $CONFIG 2> /dev/null || true |
117 | if [[ ! -e $CONFIG || -z $user ]]; then | 116 | if [[ ! -e $CONFIG || -z $user ]]; then |
118 | echo 'Hi fellow! To access your gists, I need your Github username' | 117 | echo 'Hi fellow! To access your gists, I need your Github username' |
@@ -131,12 +130,16 @@ _apply_config() { | |||
131 | return 1 | 130 | return 1 |
132 | fi | 131 | fi |
133 | fi | 132 | fi |
133 | } | ||
134 | 134 | ||
135 | source $CONFIG | 135 | # load configuration |
136 | _apply_config() { | ||
137 | source $CONFIG && _validate_config | ||
136 | 138 | ||
139 | AUTH_HEADER="Authorization: token $token" | ||
140 | [[ -z "$action" ]] && action="${EDITOR:-vi} *" | ||
137 | [[ -z "$folder" ]] && folder=~/gist && mkdir -p $folder | 141 | [[ -z "$folder" ]] && folder=~/gist && mkdir -p $folder |
138 | INDEX=$folder/index | 142 | INDEX=$folder/index |
139 | AUTH_HEADER="Authorization: token $token" | ||
140 | } | 143 | } |
141 | 144 | ||
142 | _apply_config "$@" || exit 1 | 145 | _apply_config "$@" || exit 1 |
@@ -302,6 +305,7 @@ _goto_gist() { | |||
302 | fi | 305 | fi |
303 | fi | 306 | fi |
304 | 307 | ||
308 | (cd $folder/$GIST_ID && eval "$action") | ||
305 | echo $folder/$GIST_ID | 309 | echo $folder/$GIST_ID |
306 | } | 310 | } |
307 | 311 | ||