diff options
Diffstat (limited to 'scripts/gist')
| -rwxr-xr-x | scripts/gist | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/scripts/gist b/scripts/gist index 7d90336..80996b1 100755 --- a/scripts/gist +++ b/scripts/gist | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | # gist | 17 | # gist |
| 18 | # | 18 | # |
| 19 | # * clone gist repos which are not in local | 19 | # * clone gist repos which are not in local |
| 20 | # * pull master branch if a local repo is behind its remote | ||
| 20 | # gist [sync | s] | 21 | # gist [sync | s] |
| 21 | # | 22 | # |
| 22 | # * Go to local gist repo | 23 | # * Go to local gist repo |
| @@ -54,26 +55,39 @@ index=$folder/index | |||
| 54 | 55 | ||
| 55 | # Show the list of gist, but not updated time | 56 | # Show the list of gist, but not updated time |
| 56 | _show_list() { | 57 | _show_list() { |
| 57 | cat $index | cut -d' ' -f1-2,4- | 58 | cat $index | cut -d' ' -f1-2,4- |
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | # get the list of gists | 61 | # get the list of gists |
| 61 | _update() { | 62 | _update() { |
| 62 | curl -s -H "$auth_header" $github_api/users/$user/gists |\ | 63 | curl -s -H "$auth_header" $github_api/users/$user/gists |\ |
| 63 | jq '.[] | "\(.html_url) \(.updated_at) \(.files | keys | length) \(.comments) \(.description)"' |\ | 64 | tee jojo |\ |
| 64 | tr -d '"' | tac | nl |\ | 65 | jq '.[] | "\(.html_url) \([.files[] | .raw_url]) \(.files | keys | length) \(.comments) \(.description)"' |\ |
| 65 | while read line_num link file_num comment_num description; do | 66 | tac | nl |\ |
| 66 | echo $line_num $link $file_num $comment_num $(echo $description | cut -c -80) | 67 | while read line_num link blobs file_num comment_num description; do |
| 68 | blob_code=$(echo $blobs | jq -r '.[]' | sed -r 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -sd '-') | ||
| 69 | echo $line_num $link $blob_code $file_num $comment_num $(echo $description | cut -c -80) | tr -d '"' | ||
| 67 | done > $index && \ | 70 | done > $index && \ |
| 68 | _show_list | 71 | _show_list |
| 69 | } | 72 | } |
| 70 | 73 | ||
| 71 | # clone repos which are not in the local | ||
| 72 | # TODO pull if repo is outdated | ||
| 73 | _sync_repos() { | 74 | _sync_repos() { |
| 75 | # clone repos which are not in the local | ||
| 74 | comm -13 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \ | 76 | comm -13 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \ |
| 75 | <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ | 77 | <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ |
| 76 | xargs -I{} git clone git@github.com:{}.git $folder/{} | 78 | xargs -I{} git clone git@github.com:{}.git $folder/{} |
| 79 | |||
| 80 | # pull if remote repo has different blob objects | ||
| 81 | cat $index | cut -d' ' -f2,3 |\ | ||
| 82 | while read url blob_code_remote; do | ||
| 83 | repo=$folder/$(echo $url | sed 's#.*/##') | ||
| 84 | blob_code_local=$(cd $repo && git ls-tree master | cut -d' ' -f3 | cut -c-7 | sort | paste -sd '-') | ||
| 85 | |||
| 86 | cd $repo && \ | ||
| 87 | [[ $blob_code_local != $blob_code_remote ]] && \ | ||
| 88 | [[ $(git rev-parse origin/master) == $(git rev-parse master) ]] && \ | ||
| 89 | git pull | ||
| 90 | done | ||
| 77 | } | 91 | } |
| 78 | 92 | ||
| 79 | _gist_id() { | 93 | _gist_id() { |