diff options
author | typebrook <typebrook@gmail.com> | 2019-12-24 12:16:32 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2019-12-24 12:16:32 +0800 |
commit | 6fd7094002770d43d34c289096d2164f98ef8846 (patch) | |
tree | 362f71be0c7b8efdfa6e7b10a4c4d588bf65e3e5 /scripts/gist | |
parent | 82d194a2b7461f1c6d924721d29cdb36d06d4567 (diff) |
update
Diffstat (limited to 'scripts/gist')
-rwxr-xr-x | scripts/gist/gist | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/scripts/gist/gist b/scripts/gist/gist index e739b2d..dfe7a50 100755 --- a/scripts/gist/gist +++ b/scripts/gist/gist | |||
@@ -1,14 +1,17 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | github_api_token=$(cat $SETTING_DIR/tokens/github) | 3 | github_api_token=$(cat $SETTING_DIR/tokens/github) |
4 | 4 | user=typebrook | |
5 | folder=~/git/gist | 5 | folder=~/git/gist |
6 | |||
6 | mkdir -p $folder | 7 | mkdir -p $folder |
7 | index=$folder/index | 8 | index=$folder/index |
8 | 9 | ||
10 | custom_action='tig --all' | ||
11 | |||
9 | function _update() { | 12 | function _update() { |
10 | # get the list of gists | 13 | # get the list of gists |
11 | curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/users/typebrook/gists |\ | 14 | curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/users/$user/gists |\ |
12 | jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ | 15 | jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ |
13 | tr -d '"' | tac | nl |\ | 16 | tr -d '"' | tac | nl |\ |
14 | while read line_num link file_num description; do | 17 | while read line_num link file_num description; do |
@@ -21,9 +24,10 @@ function _update() { | |||
21 | xargs -I{} git clone git@github.com:{}.git $folder/{} | 24 | xargs -I{} git clone git@github.com:{}.git $folder/{} |
22 | } | 25 | } |
23 | 26 | ||
24 | function _get_gist() { | 27 | function _go_to_gist() { |
25 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') | 28 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') |
26 | cd $folder/$GIST_ID && tig --all | 29 | cd $folder/$GIST_ID |
30 | eval $custom_action | ||
27 | } | 31 | } |
28 | 32 | ||
29 | if [[ $# -eq 0 ]]; then | 33 | if [[ $# -eq 0 ]]; then |
@@ -37,6 +41,6 @@ case "$1" in | |||
37 | ;; | 41 | ;; |
38 | 42 | ||
39 | *) | 43 | *) |
40 | _get_gist $1 | 44 | _go_to_gist $1 |
41 | ;; | 45 | ;; |
42 | esac | 46 | esac |