aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/gist
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2019-12-25 18:28:15 +0800
committertypebrook <typebrook@gmail.com>2019-12-25 18:28:15 +0800
commite4874a61f416e53e90f34a135c342745f0f3ef47 (patch)
tree1749221def842ef027310b3be2688308cd28399a /scripts/gist
parent2a1cca0c60d20c2d6f6abd857e09a569c7ca07c3 (diff)
update
Diffstat (limited to 'scripts/gist')
-rwxr-xr-xscripts/gist20
1 files changed, 11 insertions, 9 deletions
diff --git a/scripts/gist b/scripts/gist
index 284edd0..639709e 100755
--- a/scripts/gist
+++ b/scripts/gist
@@ -1,5 +1,6 @@
1#!/bin/bash 1#!/bin/bash
2 2
3# define your environmemnts here
3github_api_token=$(cat $SETTING_DIR/tokens/github) 4github_api_token=$(cat $SETTING_DIR/tokens/github)
4user=typebrook 5user=typebrook
5folder=~/git/gist 6folder=~/git/gist
@@ -20,6 +21,7 @@ _update() {
20} 21}
21 22
22# clone repos which are not in the local 23# clone repos which are not in the local
24# TODO pull if repo is outdated
23_sync_repos() { 25_sync_repos() {
24 comm -13 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \ 26 comm -13 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \
25 <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ 27 <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\
@@ -37,13 +39,13 @@ _goto_gist() {
37 fi 39 fi
38 40
39 GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') 41 GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##')
40 echo this gist is at $folder/$GIST_ID 42 echo This gist is at $folder/$GIST_ID
41 cd $folder/$GIST_ID && tig --all 2> /dev/null 43 cd $folder/$GIST_ID && tig --all 2> /dev/null
42} 44}
43 45
44_delete_gist() { 46_delete_gist() {
45 GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') 47 GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##')
46 curl -X DELETE -s -H "$auth_header" $github_api/gists/$GIST_ID 48 curl -X DELETE -s -H "$auth_header" $github_api/gists/$GIST_ID && \
47 _update 49 _update
48} 50}
49 51
@@ -71,23 +73,23 @@ _create_gist() {
71 }, 73 },
72 description: ($DESC) 74 description: ($DESC)
73 }' -R -s $1 |\ 75 }' -R -s $1 |\
74 curl -s -H "$auth_header" --data @- $github_api/gists 76 curl -s -H "$auth_header" --data @- $github_api/gists > /dev/null && \
77 _update
75} 78}
76 79
80# update description of a gist
77_edit_gist() { 81_edit_gist() {
78 GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') 82 GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##')
79 83
80 jq -n --arg DESC "$2" '{ description: ($DESC) }' |\ 84 jq -n --arg DESC "$2" '{ description: ($DESC) }' |\
81 curl -X PATCH -H "$auth_header" --data @- $github_api/gists/$GIST_ID > /dev/null 85 curl -X PATCH -H "$auth_header" --data @- $github_api/gists/$GIST_ID > /dev/null && \
82 _update 86 _update
83} 87}
84 88
85if [[ $# -eq 0 ]]; then
86 cat $index
87 exit 0
88fi
89
90case "$1" in 89case "$1" in
90 "")
91 cat $index
92 ;;
91 create | c) 93 create | c)
92 _create_gist "$2" "$3" 94 _create_gist "$2" "$3"
93 ;; 95 ;;