summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2019-12-24 15:33:55 +0800
committertypebrook <typebrook@gmail.com>2019-12-24 15:33:55 +0800
commit92870b388ecfcb66eb57945d6c66375e57e4029f (patch)
treea0ae9df9c4a2570dc59a99d1d5a3fbb1189dca79
parent52e5a9e60cf0271ff4907fe50169ce318ee2ca0c (diff)
update
-rwxr-xr-xscripts/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 @@
3github_api_token=$(cat $SETTING_DIR/tokens/github) 3github_api_token=$(cat $SETTING_DIR/tokens/github)
4user=typebrook 4user=typebrook
5folder=~/git/gist 5folder=~/git/gist
6custom_action='cd $folder/$GIST_ID && tig --all'
7 6
8mkdir -p $folder 7mkdir -p $folder
9index=$folder/index 8index=$folder/index
10 9
11function _update() { 10function _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
26function _go_to_gist() { 25function _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
31function _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
36function _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
31if [[ $# -eq 0 ]]; then 43if [[ $# -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 ;;