aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/gist
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gist')
-rwxr-xr-xscripts/gist16
1 files changed, 10 insertions, 6 deletions
diff --git a/scripts/gist b/scripts/gist
index b4621bb..b96998b 100755
--- a/scripts/gist
+++ b/scripts/gist
@@ -145,8 +145,8 @@ update() {
145_configure() { 145_configure() {
146 [[ -z $@ ]] && (${EDITOR:-vi} $CONFIG) && return 0 146 [[ -z $@ ]] && (${EDITOR:-vi} $CONFIG) && return 0
147 147
148 local target="" 148 local valid_keys='user|token|folder|auto_sync|EDITOR|action'
149 if [[ $1 =~ ^(user|token|folder|auto_sync|EDITOR|action)$ ]]; then 149 if [[ $1 =~ ^($valid_keys)$ ]]; then
150 if [[ $1 == 'user' ]]; then 150 if [[ $1 == 'user' ]]; then
151 [[ -z $2 ]] && echo "Must specify username" >&2 && return 1 151 [[ -z $2 ]] && echo "Must specify username" >&2 && return 1
152 elif [[ $1 == 'token' ]]; then 152 elif [[ $1 == 'token' ]]; then
@@ -155,7 +155,10 @@ _configure() {
155 elif [[ $1 == 'auto_sync' ]]; then 155 elif [[ $1 == 'auto_sync' ]]; then
156 [[ ! $2 =~ ^(true|false)$ ]] && return 1 156 [[ ! $2 =~ ^(true|false)$ ]] && return 1
157 fi 157 fi
158 local key=$1 && shift && target=$key=\'$@\' 158 local key=$1 && shift && local target=$key=\'$@\'
159 else
160 echo "Not a valid key for configuration, use <$valid_keys> instead."
161 return 1
159 fi 162 fi
160 163
161 umask 0077 && touch $CONFIG 164 umask 0077 && touch $CONFIG
@@ -172,8 +175,8 @@ _ask_username() {
172 _configure user $user 175 _configure user $user
173} 176}
174 177
175# prompt for toekn 178# prompt for token
176# TODO token check, ref: https://developer.github.com/v3/apps/oauth_applications/#check-a-token 179# TODO check token scope contains gist, ref: https://developer.github.com/v3/apps/oauth_applications/#check-a-token
177_ask_token() { 180_ask_token() {
178 echo -n "Create a new token from web browser? [Y/n] " 181 echo -n "Create a new token from web browser? [Y/n] "
179 read answer < /dev/tty 182 read answer < /dev/tty
@@ -266,9 +269,10 @@ _grep_content() {
266 _show_list | grep -i $1 269 _show_list | grep -i $1
267} 270}
268 271
272# Open Github repository import page
269_import_to_github() { 273_import_to_github() {
270 _gist_id $1 274 _gist_id $1
271 echo put the folowing URL into webpage: 275 echo put the folowing URL into web page:
272 echo -n git@github.com:$GIST_ID.git 276 echo -n git@github.com:$GIST_ID.git
273 python -mwebbrowser https://github.com/new/import 277 python -mwebbrowser https://github.com/new/import
274} 278}