diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/gist/gist | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/scripts/gist/gist b/scripts/gist/gist index 027db8c..200ed5a 100755 --- a/scripts/gist/gist +++ b/scripts/gist/gist | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | github_api_token=$(cat $SETTING_DIR/tokens/github) | 3 | github_api_token=$(cat $SETTING_DIR/tokens/github) |
| 4 | 4 | ||
| 5 | function _update(){ | 5 | function _update() { |
| 6 | curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/users/typebrook/gists |\ | 6 | curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/users/typebrook/gists |\ |
| 7 | jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ | 7 | jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ |
| 8 | tr -d '"' | tac | nl |\ | 8 | tr -d '"' | tac | nl |\ |
| @@ -11,12 +11,24 @@ function _update(){ | |||
| 11 | done | tee ~/.gist | 11 | done | tee ~/.gist |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | function _get_gist() { | ||
| 15 | GIST_ID=$(cat ~/.gist | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/([^/]+)$#\1#') | ||
| 16 | |||
| 17 | curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/gists/$GIST_ID |\ | ||
| 18 | jq .files | ||
| 19 | } | ||
| 20 | |||
| 21 | if [[ $# -eq 0 ]]; then | ||
| 22 | cat ~/.gist | ||
| 23 | exit 0 | ||
| 24 | fi | ||
| 25 | |||
| 14 | case "$1" in | 26 | case "$1" in |
| 15 | update | u) | 27 | update | u) |
| 16 | _update | 28 | _update |
| 17 | ;; | 29 | ;; |
| 18 | 30 | ||
| 19 | *) | 31 | *) |
| 20 | cat ~/.gist | 32 | _get_gist $1 |
| 21 | ;; | 33 | ;; |
| 22 | esac | 34 | esac |