diff options
author | typebrook <typebrook@gmail.com> | 2019-12-24 16:32:35 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2019-12-24 16:32:35 +0800 |
commit | 2f687bedf81f26eae1f5889b09f87bef9d4e3238 (patch) | |
tree | 3e4ef99f83010b702f53a000144b210a96f81c81 | |
parent | 92870b388ecfcb66eb57945d6c66375e57e4029f (diff) |
update
-rwxr-xr-x | scripts/gist | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/scripts/gist b/scripts/gist index 45572a4..879bc3d 100755 --- a/scripts/gist +++ b/scripts/gist | |||
@@ -7,7 +7,7 @@ folder=~/git/gist | |||
7 | mkdir -p $folder | 7 | mkdir -p $folder |
8 | index=$folder/index | 8 | index=$folder/index |
9 | 9 | ||
10 | function _update() { | 10 | _update() { |
11 | # get the list of gists | 11 | # get the list of gists |
12 | curl -s -H "Authorization: token $github_api_token" https://api.github.com/users/$user/gists |\ | 12 | curl -s -H "Authorization: token $github_api_token" https://api.github.com/users/$user/gists |\ |
13 | jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ | 13 | jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ |
@@ -22,23 +22,34 @@ function _update() { | |||
22 | xargs -I{} git clone git@github.com:{}.git $folder/{} | 22 | xargs -I{} git clone git@github.com:{}.git $folder/{} |
23 | } | 23 | } |
24 | 24 | ||
25 | function _go_to_gist() { | 25 | _go_to_gist() { |
26 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') | 26 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') |
27 | echo this gist is at $folder/$GIST_ID | 27 | echo this gist is at $folder/$GIST_ID |
28 | cd $folder/$GIST_ID && tig --all 2> /dev/null | 28 | cd $folder/$GIST_ID && tig --all 2> /dev/null |
29 | } | 29 | } |
30 | 30 | ||
31 | function _show_detail() { | 31 | _show_detail() { |
32 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') | 32 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') |
33 | curl -s -H "Authorization: token $github_api_token" https://api.github.com/gists/$GIST_ID | 33 | curl -s -H "Authorization: token $github_api_token" https://api.github.com/gists/$GIST_ID |
34 | } | 34 | } |
35 | 35 | ||
36 | function _create() { | 36 | # FIXME cannot upload a file |
37 | _create() { | ||
37 | curl -v -H "Authorization: token $github_api_token" \ | 38 | curl -v -H "Authorization: token $github_api_token" \ |
38 | --data '{"public":true,"files":{"foo.gpx":{"content":"$2"}}}' \ | 39 | --data "$(generate_post_data $1 | tee json)" \ |
39 | https://api.github.com/gists | 40 | https://api.github.com/gists |
40 | } | 41 | } |
41 | 42 | ||
43 | generate_post_data() { | ||
44 | cat <<EOF | ||
45 | { | ||
46 | "public": true, | ||
47 | "files": { "$1": {"content": "$(cat $1 | sed 's/"/\\\"/g' | tr '\n' ',')"}}, | ||
48 | "description": $2 | ||
49 | } | ||
50 | EOF | ||
51 | } | ||
52 | |||
42 | 53 | ||
43 | if [[ $# -eq 0 ]]; then | 54 | if [[ $# -eq 0 ]]; then |
44 | cat $index | 55 | cat $index |