diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/gist (renamed from scripts/gist/gist) | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/scripts/gist/gist b/scripts/gist index 79d028f..45572a4 100755 --- a/scripts/gist/gist +++ b/scripts/gist | |||
@@ -3,14 +3,13 @@ | |||
3 | github_api_token=$(cat $SETTING_DIR/tokens/github) | 3 | github_api_token=$(cat $SETTING_DIR/tokens/github) |
4 | user=typebrook | 4 | user=typebrook |
5 | folder=~/git/gist | 5 | folder=~/git/gist |
6 | custom_action='cd $folder/$GIST_ID && tig --all' | ||
7 | 6 | ||
8 | mkdir -p $folder | 7 | mkdir -p $folder |
9 | index=$folder/index | 8 | index=$folder/index |
10 | 9 | ||
11 | function _update() { | 10 | function _update() { |
12 | # get the list of gists | 11 | # get the list of gists |
13 | curl -s -H "Authorization: OAuth $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 |\ |
14 | jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ | 13 | jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ |
15 | tr -d '"' | tac | nl |\ | 14 | tr -d '"' | tac | nl |\ |
16 | while read line_num link file_num description; do | 15 | while read line_num link file_num description; do |
@@ -25,9 +24,22 @@ function _update() { | |||
25 | 24 | ||
26 | function _go_to_gist() { | 25 | function _go_to_gist() { |
27 | 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#.*/##') |
28 | eval $custom_action &> /dev/null || 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 | ||
29 | } | 29 | } |
30 | 30 | ||
31 | function _show_detail() { | ||
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 | ||
34 | } | ||
35 | |||
36 | function _create() { | ||
37 | curl -v -H "Authorization: token $github_api_token" \ | ||
38 | --data '{"public":true,"files":{"foo.gpx":{"content":"$2"}}}' \ | ||
39 | https://api.github.com/gists | ||
40 | } | ||
41 | |||
42 | |||
31 | if [[ $# -eq 0 ]]; then | 43 | if [[ $# -eq 0 ]]; then |
32 | cat $index | 44 | cat $index |
33 | exit 0 | 45 | exit 0 |
@@ -38,6 +50,14 @@ case "$1" in | |||
38 | _update | 50 | _update |
39 | ;; | 51 | ;; |
40 | 52 | ||
53 | detail | d) | ||
54 | _show_detail $2 | ||
55 | ;; | ||
56 | |||
57 | create | c) | ||
58 | _create $2 | ||
59 | ;; | ||
60 | |||
41 | *) | 61 | *) |
42 | _go_to_gist $1 | 62 | _go_to_gist $1 |
43 | ;; | 63 | ;; |