From 92870b388ecfcb66eb57945d6c66375e57e4029f Mon Sep 17 00:00:00 2001 From: typebrook Date: Tue, 24 Dec 2019 15:33:55 +0800 Subject: update --- scripts/gist | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/gist/gist | 44 -------------------------------------- 2 files changed, 64 insertions(+), 44 deletions(-) create mode 100755 scripts/gist delete mode 100755 scripts/gist/gist (limited to 'scripts/gist') diff --git a/scripts/gist b/scripts/gist new file mode 100755 index 0000000..45572a4 --- /dev/null +++ b/scripts/gist @@ -0,0 +1,64 @@ +#!/bin/bash + +github_api_token=$(cat $SETTING_DIR/tokens/github) +user=typebrook +folder=~/git/gist + +mkdir -p $folder +index=$folder/index + +function _update() { + # get the list of gists + curl -s -H "Authorization: token $github_api_token" https://api.github.com/users/$user/gists |\ + jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ + tr -d '"' | tac | nl |\ + while read line_num link file_num description; do + echo $line_num $link $file_num $(echo $description | cut -c -70) + done | tee $index + + # clone repos which are not in the local machine + comm -13 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \ + <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ + xargs -I{} git clone git@github.com:{}.git $folder/{} +} + +function _go_to_gist() { + GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') + echo this gist is at $folder/$GIST_ID + cd $folder/$GIST_ID && tig --all 2> /dev/null +} + +function _show_detail() { + GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') + curl -s -H "Authorization: token $github_api_token" https://api.github.com/gists/$GIST_ID +} + +function _create() { + curl -v -H "Authorization: token $github_api_token" \ + --data '{"public":true,"files":{"foo.gpx":{"content":"$2"}}}' \ + https://api.github.com/gists +} + + +if [[ $# -eq 0 ]]; then + cat $index + exit 0 +fi + +case "$1" in + update | u) + _update + ;; + + detail | d) + _show_detail $2 + ;; + + create | c) + _create $2 + ;; + + *) + _go_to_gist $1 + ;; +esac diff --git a/scripts/gist/gist b/scripts/gist/gist deleted file mode 100755 index 79d028f..0000000 --- a/scripts/gist/gist +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -github_api_token=$(cat $SETTING_DIR/tokens/github) -user=typebrook -folder=~/git/gist -custom_action='cd $folder/$GIST_ID && tig --all' - -mkdir -p $folder -index=$folder/index - -function _update() { - # get the list of gists - curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/users/$user/gists |\ - jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ - tr -d '"' | tac | nl |\ - while read line_num link file_num description; do - echo $line_num $link $file_num $(echo $description | cut -c -70) - done | tee $index - - # clone repos which are not in the local machine - comm -13 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \ - <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ - xargs -I{} git clone git@github.com:{}.git $folder/{} -} - -function _go_to_gist() { - GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') - eval $custom_action &> /dev/null || echo this gist is at $folder/$GIST_ID -} - -if [[ $# -eq 0 ]]; then - cat $index - exit 0 -fi - -case "$1" in - update | u) - _update - ;; - - *) - _go_to_gist $1 - ;; -esac -- cgit v1.2.3-70-g09d2