diff options
| -rwxr-xr-x | scripts/gist | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/scripts/gist b/scripts/gist index 58a2b78..e557339 100755 --- a/scripts/gist +++ b/scripts/gist | |||
| @@ -11,9 +11,9 @@ | |||
| 11 | # [star | s] list your gists with format below, star for your starred gists: | 11 | # [star | s] list your gists with format below, star for your starred gists: |
| 12 | # [index_of_gist] [url] [file_num] [comment_num] [short description] | 12 | # [index_of_gist] [url] [file_num] [comment_num] [short description] |
| 13 | # update, u [star | s] update the local list of your gists, star for your starred gists | 13 | # update, u [star | s] update the local list of your gists, star for your starred gists |
| 14 | # <index_of_gist> show the path of local gist repo and files | 14 | # <index_of_gist> show the path of local gist repo and do custom actions |
| 15 | # new, n [-d | --desc <description>] <files>... create a new gist with files | 15 | # new, n [-d | --desc <description>] <files>... create a new gist with files |
| 16 | # new, n [-d | --desc <description>] [-f | --file <file_name>] < <file-with-content> create a new gist from STDIN | 16 | # new, n [-d | --desc <description>] [-f | --file <file_name>] create a new gist from STDIN |
| 17 | # detail, d <index_of_gist> show the detail of a gist | 17 | # detail, d <index_of_gist> show the detail of a gist |
| 18 | # edit, e <index_of_gist> edit a gist description | 18 | # edit, e <index_of_gist> edit a gist description |
| 19 | # delete, D <index_of_gist>... delete a gist | 19 | # delete, D <index_of_gist>... delete a gist |
| @@ -26,8 +26,8 @@ | |||
| 26 | # gist (Show your gists) | 26 | # gist (Show your gists) |
| 27 | # gist 3 (show the repo path of your 3rd gist, and do custom actions) | 27 | # gist 3 (show the repo path of your 3rd gist, and do custom actions) |
| 28 | # | 28 | # |
| 29 | # Since now a gist is a local cloned repo | 29 | # Since now a gist is a local cloned repo |
| 30 | # It is your business to do git commit and git push | 30 | # It is your business to do git commit and git push |
| 31 | 31 | ||
| 32 | # TODO grep mode for description, file content | 32 | # TODO grep mode for description, file content |
| 33 | # TODO push github.com (may need new token) | 33 | # TODO push github.com (may need new token) |
| @@ -172,7 +172,7 @@ _show_list() { | |||
| 172 | local filter='/^s/ d; /^$/ d' | 172 | local filter='/^s/ d; /^$/ d' |
| 173 | [[ $1 == "s" ]] && filter='/^[^s]/ d; /^$/ d' | 173 | [[ $1 == "s" ]] && filter='/^[^s]/ d; /^$/ d' |
| 174 | 174 | ||
| 175 | while read index link blob_code file_num extra description; do | 175 | while read index link blob_code file_num extra author description; do |
| 176 | local repo=$folder/$(echo $link | sed 's#.*/##') | 176 | local repo=$folder/$(echo $link | sed 's#.*/##') |
| 177 | local occupy=0 | 177 | local occupy=0 |
| 178 | 178 | ||
| @@ -206,6 +206,7 @@ for gist in raw: | |||
| 206 | print(gist["public"], end=" ") | 206 | print(gist["public"], end=" ") |
| 207 | print(len(gist["files"]), end=" ") | 207 | print(len(gist["files"]), end=" ") |
| 208 | print(gist["comments"], end=" ") | 208 | print(gist["comments"], end=" ") |
| 209 | print(gist["owner"]["login"], end=" ") | ||
| 209 | print(gist["description"]) | 210 | print(gist["description"]) |
| 210 | ' | 211 | ' |
| 211 | } | 212 | } |
| @@ -215,14 +216,15 @@ for gist in raw: | |||
| 215 | _parse_response() { | 216 | _parse_response() { |
| 216 | AccessJsonElement "$(_handle_gists)" \ | 217 | AccessJsonElement "$(_handle_gists)" \ |
| 217 | | tac | sed 's/, /,/g' | nl -s' ' \ | 218 | | tac | sed 's/, /,/g' | nl -s' ' \ |
| 218 | | while read index link file_url_array public file_num comment_num description; do | 219 | | while read index link file_url_array public file_num comment_num author description; do |
| 219 | local blob_code=$(echo $file_url_array | tr ',' '\n' | sed -E 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -sd '-') | 220 | local blob_code=$(echo $file_url_array | tr ',' '\n' | sed -E 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -sd '-') |
| 220 | [[ $public == 'False' ]] && local mark=p | 221 | [[ $public == 'False' ]] && local mark=p |
| 221 | [[ -n $1 ]] && local index=$1 | 222 | [[ -n $1 ]] && local index=$1 |
| 222 | echo $mark$index $link $blob_code $file_num $comment_num $description | tr -d '"' | 223 | echo $mark$index $link $blob_code $file_num $comment_num $author $description | tr -d '"' |
| 223 | done | 224 | done |
| 224 | } | 225 | } |
| 225 | 226 | ||
| 227 | # TODO add author, files and date of a gist | ||
| 226 | # get latest list of gists from Github API | 228 | # get latest list of gists from Github API |
| 227 | _update() { | 229 | _update() { |
| 228 | echo "fetching $user's gists from $GITHUB_API..." | 230 | echo "fetching $user's gists from $GITHUB_API..." |