From 2fd80972761f3fd001526799887a6e135f7d108b Mon Sep 17 00:00:00 2001 From: typebrook Date: Tue, 24 Dec 2019 18:46:14 +0800 Subject: update --- scripts/gist | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'scripts/gist') diff --git a/scripts/gist b/scripts/gist index f815e3e..558b659 100755 --- a/scripts/gist +++ b/scripts/gist @@ -15,14 +15,16 @@ _update() { while read line_num link file_num description; do echo $line_num $link $file_num $(echo $description | cut -c -70) done | tee $index +} +_sync_repos() { # 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/{} } -_go_to_gist() { +_goto_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 @@ -34,15 +36,21 @@ _delete_gist() { _update } +_clean_repos() { + comm -23 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \ + <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ + xargs -I{} rm -rf $folder/{} +} + _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 } -_create() { +_create_gist() { FILE=$(basename $1) - jq --arg FILE "$FILE" --arg DESC ""$2"" '. as $content | { + jq --arg FILE "$FILE" --arg DESC "$2" '. as $content | { public: true, files: { ($FILE): {content: $content} @@ -61,18 +69,24 @@ fi case "$1" in create | c) - _create $2 $3 + _create_gist $2 "$3" ;; update | u) _update ;; + sync | s) + _sync_repos + ;; detail | d) _show_detail $2 ;; delete | D) _delete_gist $2 ;; + clean | C) + _clean_repos + ;; *) - _go_to_gist $2 + _goto_gist $1 ;; esac -- cgit v1.2.3-70-g09d2