diff options
Diffstat (limited to 'scripts/gist')
| -rwxr-xr-x | scripts/gist | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/scripts/gist b/scripts/gist index 9dfa31d..b55012b 100755 --- a/scripts/gist +++ b/scripts/gist | |||
| @@ -49,6 +49,9 @@ auth_header="Authorization: token $github_api_token" | |||
| 49 | mkdir -p $folder | 49 | mkdir -p $folder |
| 50 | index=$folder/index | 50 | index=$folder/index |
| 51 | 51 | ||
| 52 | # Validate settings. | ||
| 53 | [ "$TRACE" ] && set -x && echo foo | ||
| 54 | |||
| 52 | # get the list of gists | 55 | # get the list of gists |
| 53 | _update() { | 56 | _update() { |
| 54 | curl -s -H "$auth_header" $github_api/users/$user/gists |\ | 57 | curl -s -H "$auth_header" $github_api/users/$user/gists |\ |
| @@ -107,15 +110,19 @@ _show_detail() { | |||
| 107 | # create a new gist with a file and description | 110 | # create a new gist with a file and description |
| 108 | # TODO support folder of files | 111 | # TODO support folder of files |
| 109 | _create_gist() { | 112 | _create_gist() { |
| 110 | FILE=$(basename $1) | 113 | echo -n 'description: ' |
| 114 | read DESC | ||
| 111 | 115 | ||
| 112 | jq --arg FILE "$FILE" --arg DESC "$2" '. as $content | { | 116 | echo $@ | tr " " "\n" |\ |
| 113 | public: true, | 117 | while read file; do |
| 114 | files: { | 118 | FILE=$(basename $file) |
| 115 | ($FILE): {content: $content} | 119 | jq --arg FILE "$FILE" '. as $content | { ($FILE): {content: $content} }' -Rs $file |
| 116 | }, | 120 | done |\ |
| 121 | jq -s --arg DESC "$DESC" '{ | ||
| 122 | public: true, | ||
| 123 | files: add, | ||
| 117 | description: ($DESC) | 124 | description: ($DESC) |
| 118 | }' -R -s $1 |\ | 125 | }' |\ |
| 119 | curl -s -H "$auth_header" --data @- $github_api/gists > /dev/null && \ | 126 | curl -s -H "$auth_header" --data @- $github_api/gists > /dev/null && \ |
| 120 | _update | 127 | _update |
| 121 | } | 128 | } |
| @@ -134,7 +141,8 @@ case "$1" in | |||
| 134 | cat $index | 141 | cat $index |
| 135 | ;; | 142 | ;; |
| 136 | create | c) | 143 | create | c) |
| 137 | _create_gist "$2" "$3" | 144 | shift; |
| 145 | _create_gist $@ | ||
| 138 | ;; | 146 | ;; |
| 139 | edit | e) | 147 | edit | e) |
| 140 | _edit_gist "$2" "$3" | 148 | _edit_gist "$2" "$3" |