summaryrefslogtreecommitdiffhomepage
path: root/scripts/gist
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gist')
-rwxr-xr-xscripts/gist21
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
7mkdir -p $folder 7mkdir -p $folder
8index=$folder/index 8index=$folder/index
9 9
10function _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
25function _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
31function _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
36function _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
43generate_post_data() {
44cat <<EOF
45{
46 "public": true,
47 "files": { "$1": {"content": "$(cat $1 | sed 's/"/\\\"/g' | tr '\n' ',')"}},
48 "description": $2
49}
50EOF
51}
52
42 53
43if [[ $# -eq 0 ]]; then 54if [[ $# -eq 0 ]]; then
44 cat $index 55 cat $index