From b747017036f18b3dfc98f363233a53bba4b95143 Mon Sep 17 00:00:00 2001 From: typebrook Date: Mon, 23 Dec 2019 13:21:10 +0800 Subject: update --- alias | 3 ++- scripts/gist/gist | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/alias b/alias index a69307d..f3fe1da 100644 --- a/alias +++ b/alias @@ -71,7 +71,7 @@ alias ce='crontab -e' # ranger alias r='_ranger-cd' alias ranrc='vim ~/.config/ranger/rc.conf' -function ranger-cd() { +_ranger-cd() { tempfile="$(mktemp -t tmp.XXXXXX)" ranger --choosedir="$tempfile" "${@:-$(pwd)}" test -f "$tempfile" && @@ -245,3 +245,4 @@ alias cdand='cd ~/git/sample' repo='git@github.com' hub='https://github.com' typebrook='git@github.com:typebrook' +GITHUB_API='https://api.github.com' 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