From 7758022c3c3f331c19eb4bb304fbd72863c20855 Mon Sep 17 00:00:00 2001 From: typebrook Date: Fri, 15 May 2020 22:38:38 +0800 Subject: Add this gist as s0, the first starred gist --- gist | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/gist b/gist index 31ff937..e883087 100755 --- a/gist +++ b/gist @@ -247,26 +247,29 @@ _color_description_title() { } # Return git status of a given repo +# $1 for repo path, $2 for blob_code from last fetch _check_repo_status() { - if [[ ! -d $1 ]]; then - if [[ $auto_sync != false ]]; then - echo "\e[32m[cloning]\e[0m"; - else - echo "\e[32m[Not cloned yet]\e[0m"; - fi + if [[ $2 == NONE ]]; then + return 0 + elif [[ ! -d $1 ]]; then + if [[ $auto_sync != false ]]; then + echo "\e[32m[cloning]\e[0m"; else - cd "$1" || exit 1 - # git status is not clean or working on non-master branch - if [[ -n $(git status --short) || $(cat .git/HEAD) != 'ref: refs/heads/master' ]] &>/dev/null; then - echo "\e[36m[working]\e[0m" - else - # files contents are not the same with the last time called GIST API, so warn user to call 'gist fetch' - [[ $(_blob_code "$1") != "$2" ]] 2>/dev/null && local status="\e[31m[outdated]\e[0m" - # current HEAD is newer than remote, warn user to call 'git push' - [[ -n $(git cherry) ]] 2>/dev/null && local status="\e[31m[ahead]\e[0m" - echo "$status" - fi + echo "\e[32m[Not cloned yet]\e[0m"; fi + else + cd "$1" || exit 1 + # git status is not clean or working on non-master branch + if [[ -n $(git status --short) || $(cat .git/HEAD) != 'ref: refs/heads/master' ]] &>/dev/null; then + echo "\e[36m[working]\e[0m" + else + # files contents are not the same with the last time called GIST API, so warn user to call 'gist fetch' + [[ $(_blob_code "$1") != "$2" ]] 2>/dev/null && local status="\e[31m[outdated]\e[0m" + # current HEAD is newer than remote, warn user to call 'git push' + [[ -n $(git cherry) ]] 2>/dev/null && local status="\e[31m[ahead]\e[0m" + echo "$status" + fi + fi } # check given index is necessary to handle @@ -399,9 +402,11 @@ _fetch_gists() { if [[ $mark == s ]]; then route='gists/starred' prefix=s + extra="s0 https://gist.github.com/b0d2e7e67aa50298fdf8111ae7466b56 #bash,#gist NONE README.md@Markdown,gist@Shell 2 30 typebrook 2019-12-26T06:49:40Z 2020-05-15T13:00:31Z [bash-gist] A bash script for gist management" fi result=$(http_method GET $GITHUB_API/$route?per_page=100 | prefix=$prefix _parse_response) + result=$(printf "${extra:+$extra\n}$result") [[ -z $result ]] && echo 'Not a single valid gist' && return 0 sed -i'' -Ee "/^$mark/ d" $INDEX && echo "$result" >> $INDEX -- cgit v1.2.3-70-g09d2