diff options
Diffstat (limited to 'scripts/gist')
-rwxr-xr-x | scripts/gist | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/scripts/gist b/scripts/gist index 2636c2e..2a74cdb 100755 --- a/scripts/gist +++ b/scripts/gist | |||
@@ -82,7 +82,10 @@ http_method() { | |||
82 | http -b $METHOD "$@" "$header" $extra2 ;; | 82 | http -b $METHOD "$@" "$header" $extra2 ;; |
83 | esac | 83 | esac |
84 | } | 84 | } |
85 | alias httpGet='http_method GET' | 85 | |
86 | httpGet(){ | ||
87 | http_method GET "$@" | ||
88 | } | ||
86 | 89 | ||
87 | # parse JSON from STDIN with string of commands | 90 | # parse JSON from STDIN with string of commands |
88 | _process_json() { | 91 | _process_json() { |
@@ -92,11 +95,10 @@ _process_json() { | |||
92 | } | 95 | } |
93 | 96 | ||
94 | checkInternet() { | 97 | checkInternet() { |
95 | httpGET github.com > /dev/null 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query github with a get request | 98 | httpGet github.com 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query github with a get request |
96 | } | 99 | } |
97 | 100 | ||
98 | update() | 101 | update() { |
99 | { | ||
100 | # Author: Alexander Epstein https://github.com/alexanderepstein | 102 | # Author: Alexander Epstein https://github.com/alexanderepstein |
101 | # Update utility version 2.2.0 | 103 | # Update utility version 2.2.0 |
102 | # To test the tool enter in the defualt values that are in the examples for each variable | 104 | # To test the tool enter in the defualt values that are in the examples for each variable |
@@ -324,11 +326,11 @@ _fetch_gists() { | |||
324 | _query_user() { | 326 | _query_user() { |
325 | local route="users/$1/gists" | 327 | local route="users/$1/gists" |
326 | result=$(http_method GET $GITHUB_API/$route | _parse_response) | 328 | result=$(http_method GET $GITHUB_API/$route | _parse_response) |
327 | [[ -z $result ]] && echo Failed to update gists && return 1 | 329 | [[ -z $result ]] && echo "Failed to query $1's gists" && return 1 |
328 | 330 | ||
329 | echo "$result" \ | 331 | echo "$result" \ |
330 | | while read index link blob_code file_num extra description; do | 332 | | while read index link blob_code file_num extra description; do |
331 | echo $link $file_num $extra $(echo $description | cut -c -70 ) | 333 | echo $link $file_num $extra $description | cut -c -$(tput cols) |
332 | done | 334 | done |
333 | } | 335 | } |
334 | 336 | ||
@@ -337,7 +339,7 @@ _blob_code() { | |||
337 | } | 339 | } |
338 | 340 | ||
339 | # update local git repos | 341 | # update local git repos |
340 | # TODO support http protocol | 342 | # TODO support HTTPS protocol |
341 | _sync_repos() { | 343 | _sync_repos() { |
342 | # clone repos which are not in the local | 344 | # clone repos which are not in the local |
343 | comm -13 <(find $folder -maxdepth 1 -type d | sed -e '1d; s#.*/##' | sort) \ | 345 | comm -13 <(find $folder -maxdepth 1 -type d | sed -e '1d; s#.*/##' | sort) \ |
@@ -579,7 +581,7 @@ case "$1" in | |||
579 | version) | 581 | version) |
580 | echo "Version $currentVersion" | 582 | echo "Version $currentVersion" |
581 | exit 0 ;; | 583 | exit 0 ;; |
582 | update | u) | 584 | update) |
583 | checkInternet || exit 1 | 585 | checkInternet || exit 1 |
584 | update | 586 | update |
585 | exit 0 | 587 | exit 0 |