diff options
| author | typebrook <typebrook@gmail.com> | 2020-02-12 14:58:53 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-02-12 14:58:53 +0800 |
| commit | 904cd143a71ebeb54e9766608317c43a8c21005b (patch) | |
| tree | 945c115de665e4b8ea53d855d7a7b88926511db9 | |
| parent | ae35cc9d6c714e8a40aa304d2db60f1a7214b9b2 (diff) | |
update
| -rwxr-xr-x | scripts/gist | 16 |
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 | } |