diff options
| -rwxr-xr-x | scripts/gist | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/scripts/gist b/scripts/gist index f7933e1..e52d98f 100755 --- a/scripts/gist +++ b/scripts/gist | |||
| @@ -20,16 +20,16 @@ | |||
| 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 [value] ] do configuration | 21 | # config, c [token | user | folder | auto-sync | EDITOR | action [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 | ||
| 23 | # help, h show this help message | 24 | # help, h show this help message |
| 24 | # | 25 | # |
| 25 | # Example: | 26 | # Example: |
| 26 | # gist (Show your gists) | 27 | # gist (Show your gists) |
| 27 | # gist 3 (show the repo path of your 3rd gist, and do custom actions) | 28 | # gist 3 (show the repo path of your 3rd gist, and do custom actions) |
| 28 | # | 29 | # |
| 29 | # Since now a gist is a local cloned repo | 30 | # Since now a gist is a local cloned repo |
| 30 | # It is your business to do git commit and git push | 31 | # It is your business to do git commit and git push |
| 31 | 32 | ||
| 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) |
| 34 | # TODO unit test | 34 | # TODO unit test |
| 35 | # TODO test on bats, mac and remote machine | 35 | # TODO test on bats, mac and remote machine |
| @@ -164,7 +164,7 @@ _show_list() { | |||
| 164 | echo ' gist update' | 164 | echo ' gist update' |
| 165 | return 0 | 165 | return 0 |
| 166 | fi | 166 | fi |
| 167 | local filter='/^ *s/ d; /^$/ d' | 167 | [[ -z $1 ]] && filter='/^ *s/ d; /^$/ d' |
| 168 | [[ $1 == "s" ]] && filter='/^ *[^ s]/ d; /^$/ d' | 168 | [[ $1 == "s" ]] && filter='/^ *[^ s]/ d; /^$/ d' |
| 169 | 169 | ||
| 170 | while read index link blob_code file_num extra author description; do | 170 | while read index link blob_code file_num extra author description; do |
| @@ -185,6 +185,11 @@ _show_list() { | |||
| 185 | echo -e '\nrun "gist help" for more details' > /dev/tty | 185 | echo -e '\nrun "gist help" for more details' > /dev/tty |
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | # support files | ||
| 189 | _grep_content() { | ||
| 190 | _show_list other | grep -i $1 | ||
| 191 | } | ||
| 192 | |||
| 188 | # parse JSON from STDIN with string of commands | 193 | # parse JSON from STDIN with string of commands |
| 189 | AccessJsonElement() { | 194 | AccessJsonElement() { |
| 190 | PYTHONIOENCODING=utf-8 \ | 195 | PYTHONIOENCODING=utf-8 \ |
| @@ -441,7 +446,7 @@ _edit_gist() { | |||
| 441 | read DESC < /dev/tty | 446 | read DESC < /dev/tty |
| 442 | 447 | ||
| 443 | http_data=$(mktemp) | 448 | http_data=$(mktemp) |
| 444 | echo "{ \"description\": \"$DESC\" }" > $http_data | 449 | echo { \"description\": \"$(echo $DESC | sed 's/"/\\"/g')\" } > $http_data |
| 445 | http_method PATCH $http_data $GITHUB_API/gists/$GIST_ID > /dev/null \ | 450 | http_method PATCH $http_data $GITHUB_API/gists/$GIST_ID > /dev/null \ |
| 446 | && _update | 451 | && _update |
| 447 | } | 452 | } |
| @@ -480,6 +485,9 @@ case "$1" in | |||
| 480 | user | U) | 485 | user | U) |
| 481 | shift | 486 | shift |
| 482 | _query_user "$@" ;; | 487 | _query_user "$@" ;; |
| 488 | grep | g) | ||
| 489 | shift | ||
| 490 | _grep_content "$@" ;; | ||
| 483 | help | h) | 491 | help | h) |
| 484 | usage ;; | 492 | usage ;; |
| 485 | *) | 493 | *) |