diff options
| author | typebrook <typebrook@gmail.com> | 2020-05-15 22:38:38 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-05-15 22:38:38 +0800 |
| commit | 7758022c3c3f331c19eb4bb304fbd72863c20855 (patch) | |
| tree | 419bb8ab549d794941456dde3db9b60096b37632 | |
| parent | 0c6b65a9d78a108c465a0a7274600464c24fb39a (diff) | |
Add this gist as s0, the first starred gist
| -rwxr-xr-x | gist | 39 |
1 files changed, 22 insertions, 17 deletions
| @@ -247,26 +247,29 @@ _color_description_title() { | |||
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | # Return git status of a given repo | 249 | # Return git status of a given repo |
| 250 | # $1 for repo path, $2 for blob_code from last fetch | ||
| 250 | _check_repo_status() { | 251 | _check_repo_status() { |
| 251 | if [[ ! -d $1 ]]; then | 252 | if [[ $2 == NONE ]]; then |
| 252 | if [[ $auto_sync != false ]]; then | 253 | return 0 |
| 253 | echo "\e[32m[cloning]\e[0m"; | 254 | elif [[ ! -d $1 ]]; then |
| 254 | else | 255 | if [[ $auto_sync != false ]]; then |
| 255 | echo "\e[32m[Not cloned yet]\e[0m"; | 256 | echo "\e[32m[cloning]\e[0m"; |
| 256 | fi | ||
| 257 | else | 257 | else |
| 258 | cd "$1" || exit 1 | 258 | echo "\e[32m[Not cloned yet]\e[0m"; |
| 259 | # git status is not clean or working on non-master branch | ||
| 260 | if [[ -n $(git status --short) || $(cat .git/HEAD) != 'ref: refs/heads/master' ]] &>/dev/null; then | ||
| 261 | echo "\e[36m[working]\e[0m" | ||
| 262 | else | ||
| 263 | # files contents are not the same with the last time called GIST API, so warn user to call 'gist fetch' | ||
| 264 | [[ $(_blob_code "$1") != "$2" ]] 2>/dev/null && local status="\e[31m[outdated]\e[0m" | ||
| 265 | # current HEAD is newer than remote, warn user to call 'git push' | ||
| 266 | [[ -n $(git cherry) ]] 2>/dev/null && local status="\e[31m[ahead]\e[0m" | ||
| 267 | echo "$status" | ||
| 268 | fi | ||
| 269 | fi | 259 | fi |
| 260 | else | ||
| 261 | cd "$1" || exit 1 | ||
| 262 | # git status is not clean or working on non-master branch | ||
| 263 | if [[ -n $(git status --short) || $(cat .git/HEAD) != 'ref: refs/heads/master' ]] &>/dev/null; then | ||
| 264 | echo "\e[36m[working]\e[0m" | ||
| 265 | else | ||
| 266 | # files contents are not the same with the last time called GIST API, so warn user to call 'gist fetch' | ||
| 267 | [[ $(_blob_code "$1") != "$2" ]] 2>/dev/null && local status="\e[31m[outdated]\e[0m" | ||
| 268 | # current HEAD is newer than remote, warn user to call 'git push' | ||
| 269 | [[ -n $(git cherry) ]] 2>/dev/null && local status="\e[31m[ahead]\e[0m" | ||
| 270 | echo "$status" | ||
| 271 | fi | ||
| 272 | fi | ||
| 270 | } | 273 | } |
| 271 | 274 | ||
| 272 | # check given index is necessary to handle | 275 | # check given index is necessary to handle |
| @@ -399,9 +402,11 @@ _fetch_gists() { | |||
| 399 | if [[ $mark == s ]]; then | 402 | if [[ $mark == s ]]; then |
| 400 | route='gists/starred' | 403 | route='gists/starred' |
| 401 | prefix=s | 404 | prefix=s |
| 405 | 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" | ||
| 402 | fi | 406 | fi |
| 403 | 407 | ||
| 404 | result=$(http_method GET $GITHUB_API/$route?per_page=100 | prefix=$prefix _parse_response) | 408 | result=$(http_method GET $GITHUB_API/$route?per_page=100 | prefix=$prefix _parse_response) |
| 409 | result=$(printf "${extra:+$extra\n}$result") | ||
| 405 | [[ -z $result ]] && echo 'Not a single valid gist' && return 0 | 410 | [[ -z $result ]] && echo 'Not a single valid gist' && return 0 |
| 406 | 411 | ||
| 407 | sed -i'' -Ee "/^$mark/ d" $INDEX && echo "$result" >> $INDEX | 412 | sed -i'' -Ee "/^$mark/ d" $INDEX && echo "$result" >> $INDEX |