From b747017036f18b3dfc98f363233a53bba4b95143 Mon Sep 17 00:00:00 2001 From: typebrook Date: Mon, 23 Dec 2019 13:21:10 +0800 Subject: update --- scripts/gist/gist | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'scripts/gist') 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 @@ github_api_token=$(cat $SETTING_DIR/tokens/github) -function _update(){ +function _update() { curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/users/typebrook/gists |\ jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ tr -d '"' | tac | nl |\ @@ -11,12 +11,24 @@ function _update(){ done | tee ~/.gist } +function _get_gist() { + GIST_ID=$(cat ~/.gist | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/([^/]+)$#\1#') + + curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/gists/$GIST_ID |\ + jq .files +} + +if [[ $# -eq 0 ]]; then + cat ~/.gist + exit 0 +fi + case "$1" in update | u) _update ;; *) - cat ~/.gist + _get_gist $1 ;; esac -- cgit v1.2.3-70-g09d2