diff options
| author | typebrook <typebrook@gmail.com> | 2020-01-19 19:20:29 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-01-19 19:20:29 +0800 |
| commit | 0285db18316e21ea4ef15813ef69b25ca0c20b86 (patch) | |
| tree | 3bb280b3c05fdf3bdc34ed0e884fc96e6b5c47b3 /scripts | |
| parent | 52738d6d4d6e34775ddf37c785846c6c95449c81 (diff) | |
update
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/gist | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/scripts/gist b/scripts/gist index 7f8fad0..aafee26 100755 --- a/scripts/gist +++ b/scripts/gist | |||
| @@ -103,8 +103,7 @@ _update() { | |||
| 103 | curl -s -H "$auth_header" $github_api/$route |\ | 103 | curl -s -H "$auth_header" $github_api/$route |\ |
| 104 | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file && \ | 104 | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file && \ |
| 105 | _show_list $list_file | 105 | _show_list $list_file |
| 106 | #(_sync_repos $1 > /dev/null 2>&1 &) | 106 | (_sync_repos $1 > /dev/null 2>&1 &) |
| 107 | _sync_repos $1 | ||
| 108 | } | 107 | } |
| 109 | 108 | ||
| 110 | # TODO check if a user create a very first gist | 109 | # TODO check if a user create a very first gist |
| @@ -161,6 +160,7 @@ _goto_gist() { | |||
| 161 | cd $folder/$GIST_ID && ls && tig --all 2> /dev/null | 160 | cd $folder/$GIST_ID && ls && tig --all 2> /dev/null |
| 162 | } | 161 | } |
| 163 | 162 | ||
| 163 | # TODO delete multiple gists at the same time | ||
| 164 | _delete_gist() { | 164 | _delete_gist() { |
| 165 | _gist_id $1 | 165 | _gist_id $1 |
| 166 | curl -X DELETE -s -H "$auth_header" $github_api/gists/$GIST_ID && \ | 166 | curl -X DELETE -s -H "$auth_header" $github_api/gists/$GIST_ID && \ |
| @@ -197,27 +197,27 @@ _new_file() { | |||
| 197 | echo /tmp/$filename | 197 | echo /tmp/$filename |
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | _set_gist() { | ||
| 201 | for i in "$@"; do | ||
| 202 | case "$i" in | ||
| 203 | -d) | ||
| 204 | description="$2" | ||
| 205 | shift; shift;; | ||
| 206 | -f) | ||
| 207 | filename="$2" | ||
| 208 | shift; shift;; | ||
| 209 | esac | ||
| 210 | done | ||
| 211 | files=$@ | ||
| 212 | } | ||
| 213 | |||
| 200 | # create a new gist with files | 214 | # create a new gist with files |
| 215 | # FIXME error handling if gist is not created | ||
| 201 | _create_gist() { | 216 | _create_gist() { |
| 202 | for i in "$@" | 217 | _set_gist "$@" |
| 203 | do | ||
| 204 | case $i in | ||
| 205 | -d) | ||
| 206 | echo $@ | ||
| 207 | description=$2 | ||
| 208 | shift; shift | ||
| 209 | echo desc $description ;; | ||
| 210 | -f) | ||
| 211 | echo $@ | ||
| 212 | filename=$2 | ||
| 213 | shift; shift | ||
| 214 | echo filename $filename ;; | ||
| 215 | esac | ||
| 216 | done | ||
| 217 | exit 0 | ||
| 218 | 218 | ||
| 219 | files=$@ && [[ -z "$files" ]] && files=$(_new_file $filename) | 219 | [[ -z "$files" ]] && files=$(_new_file $filename) |
| 220 | [[ -z $description ]] && echo -n 'Description: ' && read description | 220 | [[ -z $description ]] && echo -n 'Description: ' && read description |
| 221 | 221 | ||
| 222 | for file in $files; do | 222 | for file in $files; do |
| 223 | FILE=$(basename $file) | 223 | FILE=$(basename $file) |
| @@ -261,7 +261,7 @@ case "$1" in | |||
| 261 | _update "$2" ;; | 261 | _update "$2" ;; |
| 262 | new | n) | 262 | new | n) |
| 263 | shift | 263 | shift |
| 264 | _create_gist $@ ;; | 264 | _create_gist "$@" ;; |
| 265 | edit | e) | 265 | edit | e) |
| 266 | _edit_gist "$2" ;; | 266 | _edit_gist "$2" ;; |
| 267 | sync | S) | 267 | sync | S) |