summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2019-12-25 12:10:48 +0800
committertypebrook <typebrook@gmail.com>2019-12-25 12:10:48 +0800
commitc4b487095fae8eff858ccf7e5d0958652c78b92a (patch)
treed95ef79d04092d2375d2f312a1f5362f374a6f29
parent28160b5e8d8b75a99518c54f64da438cee4d1cdd (diff)
update
-rw-r--r--alias1
-rwxr-xr-xscripts/gist36
-rw-r--r--tigrc2
3 files changed, 26 insertions, 13 deletions
diff --git a/alias b/alias
index 117802a..34e3876 100644
--- a/alias
+++ b/alias
@@ -242,6 +242,7 @@ alias and='cd ~/git/geoBingAn.Android'
242alias cdG='cd ~/git/git' 242alias cdG='cd ~/git/git'
243alias cdT='cd ~/git/taiwan-topo' 243alias cdT='cd ~/git/taiwan-topo'
244alias cdand='cd ~/git/sample' 244alias cdand='cd ~/git/sample'
245alias cdm='cd ~/git/sharkbig.github.io'
245 246
246repo='git@github.com' 247repo='git@github.com'
247hub='https://github.com' 248hub='https://github.com'
diff --git a/scripts/gist b/scripts/gist
index 558b659..5bfb9d6 100755
--- a/scripts/gist
+++ b/scripts/gist
@@ -4,12 +4,14 @@ github_api_token=$(cat $SETTING_DIR/tokens/github)
4user=typebrook 4user=typebrook
5folder=~/git/gist 5folder=~/git/gist
6 6
7github_api=https://api.github.com
8auth_header="Authorization: token $github_api_token"
7mkdir -p $folder 9mkdir -p $folder
8index=$folder/index 10index=$folder/index
9 11
12# get the list of gists
10_update() { 13_update() {
11 # get the list of gists 14 curl -s -H "$auth_header" $github_api/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 )"' |\ 15 jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\
14 tr -d '"' | tac | nl |\ 16 tr -d '"' | tac | nl |\
15 while read line_num link file_num description; do 17 while read line_num link file_num description; do
@@ -17,8 +19,8 @@ _update() {
17 done | tee $index 19 done | tee $index
18} 20}
19 21
22# clone repos which are not in the local
20_sync_repos() { 23_sync_repos() {
21 # clone repos which are not in the local machine
22 comm -13 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \ 24 comm -13 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \
23 <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ 25 <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\
24 xargs -I{} git clone git@github.com:{}.git $folder/{} 26 xargs -I{} git clone git@github.com:{}.git $folder/{}
@@ -32,10 +34,11 @@ _goto_gist() {
32 34
33_delete_gist() { 35_delete_gist() {
34 GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') 36 GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##')
35 curl -X DELETE -s -H "Authorization: token $github_api_token" https://api.github.com/gists/$GIST_ID 37 curl -X DELETE -s -H "$auth_header" $github_api/gists/$GIST_ID
36 _update 38 _update
37} 39}
38 40
41# remove repos which are not in user gists anymore
39_clean_repos() { 42_clean_repos() {
40 comm -23 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \ 43 comm -23 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \
41 <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ 44 <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\
@@ -44,9 +47,10 @@ _clean_repos() {
44 47
45_show_detail() { 48_show_detail() {
46 GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') 49 GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##')
47 curl -s -H "Authorization: token $github_api_token" https://api.github.com/gists/$GIST_ID 50 curl -s -H "$auth_header" $github_api/gists/$GIST_ID
48} 51}
49 52
53# create a new gist with a file and description
50_create_gist() { 54_create_gist() {
51 FILE=$(basename $1) 55 FILE=$(basename $1)
52 56
@@ -57,9 +61,14 @@ _create_gist() {
57 }, 61 },
58 description: ($DESC) 62 description: ($DESC)
59 }' -R -s $1 |\ 63 }' -R -s $1 |\
60 curl -s -H "Authorization: token $github_api_token" \ 64 curl -s -H "$auth_header" --data @- $github_api/gists
61 --data @- \ 65}
62 https://api.github.com/gists 66
67_edit_gist() {
68 GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##')
69
70 jq -n --arg DESC "$2" '{ description: ($DESC) }' |\
71 curl -X PATCH -H "$auth_header" --data @- $github_api/gists/$GIST_ID
63} 72}
64 73
65if [[ $# -eq 0 ]]; then 74if [[ $# -eq 0 ]]; then
@@ -69,7 +78,10 @@ fi
69 78
70case "$1" in 79case "$1" in
71 create | c) 80 create | c)
72 _create_gist $2 "$3" 81 _create_gist "$2" "$3"
82 ;;
83 edit | e)
84 _edit_gist "$2" "$3"
73 ;; 85 ;;
74 update | u) 86 update | u)
75 _update 87 _update
@@ -78,15 +90,15 @@ case "$1" in
78 _sync_repos 90 _sync_repos
79 ;; 91 ;;
80 detail | d) 92 detail | d)
81 _show_detail $2 93 _show_detail "$2"
82 ;; 94 ;;
83 delete | D) 95 delete | D)
84 _delete_gist $2 96 _delete_gist "$2"
85 ;; 97 ;;
86 clean | C) 98 clean | C)
87 _clean_repos 99 _clean_repos
88 ;; 100 ;;
89 *) 101 *)
90 _goto_gist $1 102 _goto_gist "$1"
91 ;; 103 ;;
92esac 104esac
diff --git a/tigrc b/tigrc
index 1bfb501..cbe3fd4 100644
--- a/tigrc
+++ b/tigrc
@@ -94,7 +94,7 @@ bind main 1 +sh -c "git rev-list --all --children | \
94bind main b none 94bind main b none
95bind main bn @git branch "%(prompt Enter branch name: )" %(commit) 95bind main bn @git branch "%(prompt Enter branch name: )" %(commit)
96bind main bN @git branch %(branch) --track %(remote)/%(branch) 96bind main bN @git branch %(branch) --track %(remote)/%(branch)
97bind main bu @git branch --set-upstream-to="%(prompt Set remote/branch: )" 97bind main bu @git branch --set-upstream-to="%(prompt Set remote: )" %(branch)
98bind main bc @git checkout -b "%(prompt Checkout at new branch: )" %(commit) 98bind main bc @git checkout -b "%(prompt Checkout at new branch: )" %(commit)
99bind generic bd @git branch -d "%(prompt Delete branch: )" 99bind generic bd @git branch -d "%(prompt Delete branch: )"
100bind main bbd @git branch -d %(branch) 100bind main bbd @git branch -d %(branch)