From dd88f09bed64367993228c9b3c4cc76027201178 Mon Sep 17 00:00:00 2001 From: typebrook Date: Tue, 19 May 2020 22:08:39 +0800 Subject: Fix error when don't pass index to 'push' --- gist | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gist b/gist index 224d271..b87da54 100755 --- a/gist +++ b/gist @@ -508,6 +508,7 @@ _repo_url() { _gist_id() { read -r ${INDEX_FORMAT[@]} <<<"$(sed -ne "/^$1 / p" $INDEX)" GIST_ID=${url##*/} + if [[ -z $GIST_ID || ! $1 =~ [0-9a-z]+ ]]; then echo -e "$(hint=false _print_records | sed -Ee 's/^( *[0-9a-z]+)/\\e[5m\1\\e[0m/')" echo @@ -621,18 +622,25 @@ _export_to_github() { python -mwebbrowser https://github.com/new/import } +_id_to_index() { + while read -r ${INDEX_FORMAT[@]}; do + [[ ! $index =~ s && ${url##*/} == $1 ]] && echo $index + done <$INDEX +} + # Simply commit current changes and push to remote _push_to_remote() { _set_gist_id $1 || return 1 cd "$folder/$GIST_ID" + local index=$(_id_to_index $GIST_ID) + if [[ -n $(git status --short) ]]; then git add . && git commit -m 'update' fi if [[ -n $(git cherry) ]]; then git push origin master && \ - http_method GET "$GITHUB_API/gists/$GIST_ID" | _update_gist $1 - # FIXME $1 might be empty + http_method GET "$GITHUB_API/gists/$GIST_ID" | _update_gist $index fi } -- cgit v1.2.3-70-g09d2