diff options
-rwxr-xr-x | gist | 31 |
1 files changed, 16 insertions, 15 deletions
@@ -8,22 +8,22 @@ | |||
8 | # Description: Manage your gists with git and Github API v3 | 8 | # Description: Manage your gists with git and Github API v3 |
9 | # Usage: gist [command] [<args>] | 9 | # Usage: gist [command] [<args>] |
10 | # | 10 | # |
11 | # [star | s] List your gists with format below, star for your starred gists: | 11 | # [star | s] List your gists, use argument 'star' for your starred gists. Format is like: |
12 | # [index_of_gist] [url] [file_num] [comment_num] [short description] | 12 | # <index_of_gist> <url> <file_num> <comment_num> <description> |
13 | # fetch, f [star | s] Update the local list of your gists, star for your starred gists | 13 | # fetch, f [star | s] Update the local list of your gists, 'star' for your starred gists |
14 | # <index_of_gist> [--no-action] Show the path of local gist repo and do custom actions | 14 | # <index_of_gist> [--no-action] Show the path of local gist repo and do custom actions |
15 | # new, n [-d | --desc <description>] [-p] <files>... create a new gist with files | 15 | # new, n [-d | --desc <description>] [-p] <file1> <file2>... create a new gist with files |
16 | # new, n [-d | --desc <description>] [-p] [-f | --file <file_name>] create a new gist from STDIN | 16 | # new, n [-d | --desc <description>] [-p] [-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's description | 18 | # edit, e <index_of_gist> Edit a gist's description |
19 | # delete, D <index_of_gist>... Delete a gist | 19 | # delete, D <index_of_gist>... Delete a gist |
20 | # clean, C Clean removed gists in local | 20 | # clean, C Clean removed gists in local |
21 | # config, c [token | user | folder | auto_sync | EDITOR | action | protocol [value] ] Do configuration | 21 | # config, c [token | user | folder | auto_sync | EDITOR | action | protocol [value] ] Do configuration |
22 | # user, U <user> Get gists from a given Github user | 22 | # user, U <user> Get gists from a given Github user |
23 | # grep, g <pattern> Grep gists by a given pattern from description, filename or file content | 23 | # grep, g <pattern> Grep gists by a given pattern |
24 | # push, p <index_of_gist> Push changes by git (well, better to make commit by youself) | 24 | # push, p <index_of_gist> Push changes by git (well, better to make commit by youself) |
25 | # github, G <index_of_gist> Import selected gist as a new Github repo | 25 | # github, G <index_of_gist> Import selected gist as a new Github repo |
26 | # help, h Show this help message | 26 | # help, h Show this help message |
27 | # version Get the tool version | 27 | # version Get the tool version |
28 | # update Update Bash-Snippet Tools | 28 | # update Update Bash-Snippet Tools |
29 | # | 29 | # |
@@ -239,7 +239,7 @@ _check_repo_status() { | |||
239 | fi | 239 | fi |
240 | else | 240 | else |
241 | cd "$1" || exit | 241 | cd "$1" || exit |
242 | if [[ -n $(git status --short) ]] &>/dev/null; then | 242 | if [[ -n $(git status --short) || $(git branch | sed -n '/\* / s///p') != 'master' ]] &>/dev/null; then |
243 | echo "\e[36m[working]\e[0m" | 243 | echo "\e[36m[working]\e[0m" |
244 | else | 244 | else |
245 | [[ $(_blob_code "$1") != "$2" ]] 2>/dev/null && echo "\e[31m[outdated]\e[0m" | 245 | [[ $(_blob_code "$1") != "$2" ]] 2>/dev/null && echo "\e[31m[outdated]\e[0m" |
@@ -336,12 +336,13 @@ _parse_response() { | |||
336 | } | 336 | } |
337 | 337 | ||
338 | # TODO pagnation for more than 100 gists | 338 | # TODO pagnation for more than 100 gists |
339 | # TODO add files and date of a gist | 339 | # TODO add files of a gist |
340 | # get latest list of gists from Github API | 340 | # get latest list of gists from Github API |
341 | _fetch_gists() { | 341 | _fetch_gists() { |
342 | echo "fetching $user's gists from $GITHUB_API..." | 342 | echo "fetching $user's gists from $GITHUB_API..." |
343 | echo | 343 | echo |
344 | local route="users/$user/gists" | 344 | local route="users/$user/gists" |
345 | local mark='' | ||
345 | if [[ $1 =~ ^(star|s)$ ]];then | 346 | if [[ $1 =~ ^(star|s)$ ]];then |
346 | route='gists/starred' | 347 | route='gists/starred' |
347 | local mark=s | 348 | local mark=s |
@@ -365,8 +366,8 @@ _query_user() { | |||
365 | [[ -z $result ]] && echo "Failed to query $1's gists" && return 1 | 366 | [[ -z $result ]] && echo "Failed to query $1's gists" && return 1 |
366 | 367 | ||
367 | echo "$result" \ | 368 | echo "$result" \ |
368 | | while read -r index link blob_code file_num extra description; do | 369 | | while read -r index link blob_code file_num comment_num author _ _ description; do |
369 | echo "$link $file_num $extra $description" | cut -c -"$(tput cols)" | 370 | echo "$link $author $file_num $comment_num $description" | cut -c -"$(tput cols)" |
370 | done | 371 | done |
371 | } | 372 | } |
372 | 373 | ||