diff options
Diffstat (limited to 'scripts/gist')
-rwxr-xr-x | scripts/gist/gist | 20 |
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 | ||
3 | github_api_token=$(cat $SETTING_DIR/tokens/github) | 3 | github_api_token=$(cat $SETTING_DIR/tokens/github) |
4 | 4 | ||
5 | folder=~/git/gist | ||
6 | mkdir -p $folder | ||
7 | index=$folder/index | ||
8 | |||
5 | function _update() { | 9 | function _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 | ||
14 | function _get_gist() { | 24 | function _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 | ||
21 | if [[ $# -eq 0 ]]; then | 29 | if [[ $# -eq 0 ]]; then |
22 | cat ~/.gist | 30 | cat $index |
23 | exit 0 | 31 | exit 0 |
24 | fi | 32 | fi |
25 | 33 | ||