diff options
| -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 |