summaryrefslogtreecommitdiffhomepage
path: root/scripts/gist
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2019-12-24 11:45:36 +0800
committertypebrook <typebrook@gmail.com>2019-12-24 11:45:36 +0800
commit223871381da8d9f9bb4dfddc35dca7ec4b942880 (patch)
tree29b8786e869f9b78836d15427ef1bdad02236ca0 /scripts/gist
parentb747017036f18b3dfc98f363233a53bba4b95143 (diff)
update
Diffstat (limited to 'scripts/gist')
-rwxr-xr-xscripts/gist/gist20
1 files changed, 14 insertions, 6 deletions
diff --git a/scripts/gist/gist b/scripts/gist/gist
index 200ed5a..ab68176 100755
--- a/scripts/gist/gist
+++ b/scripts/gist/gist
@@ -2,24 +2,32 @@
2 2
3github_api_token=$(cat $SETTING_DIR/tokens/github) 3github_api_token=$(cat $SETTING_DIR/tokens/github)
4 4
5folder=~/git/gist
6mkdir -p $folder
7index=$folder/index
8
5function _update() { 9function _update() {
10 # get the list of gists
6 curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/users/typebrook/gists |\ 11 curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/users/typebrook/gists |\
7 jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ 12 jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\
8 tr -d '"' | tac | nl |\ 13 tr -d '"' | tac | nl |\
9 while read line_num link file_num description; do 14 while read line_num link file_num description; do
10 echo $line_num $link $file_num $(echo $description | cut -c -70) 15 echo $line_num $link $file_num $(echo $description | cut -c -70)
11 done | tee ~/.gist 16 done | tee $index
17
18 # clone repos which are not in the local
19 comm -13 <(find . -maxdepth 1 -type d | sed '1d; s#\./##' | sort) \
20 <(cat index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\
21 xargs -I{} git clone git@github.com:{}.git $folder/{}
12} 22}
13 23
14function _get_gist() { 24function _get_gist() {
15 GIST_ID=$(cat ~/.gist | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/([^/]+)$#\1#') 25 GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##')
16 26 cd $folder/$GIST_ID && tig --all
17 curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/gists/$GIST_ID |\
18 jq .files
19} 27}
20 28
21if [[ $# -eq 0 ]]; then 29if [[ $# -eq 0 ]]; then
22 cat ~/.gist 30 cat $index
23 exit 0 31 exit 0
24fi 32fi
25 33