diff options
author | typebrook <typebrook@gmail.com> | 2020-05-19 22:08:39 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-05-19 22:18:04 +0800 |
commit | dd88f09bed64367993228c9b3c4cc76027201178 (patch) | |
tree | 261b601d2283c2af938dfd39011e9c62fe37b669 | |
parent | 22d08b5e59821ba0dd474fdca3da501ac665ce3b (diff) |
Fix error when don't pass index to 'push'v0.7
-rwxr-xr-x | gist | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -508,6 +508,7 @@ _repo_url() { | |||
508 | _gist_id() { | 508 | _gist_id() { |
509 | read -r ${INDEX_FORMAT[@]} <<<"$(sed -ne "/^$1 / p" $INDEX)" | 509 | read -r ${INDEX_FORMAT[@]} <<<"$(sed -ne "/^$1 / p" $INDEX)" |
510 | GIST_ID=${url##*/} | 510 | GIST_ID=${url##*/} |
511 | |||
511 | if [[ -z $GIST_ID || ! $1 =~ [0-9a-z]+ ]]; then | 512 | if [[ -z $GIST_ID || ! $1 =~ [0-9a-z]+ ]]; then |
512 | echo -e "$(hint=false _print_records | sed -Ee 's/^( *[0-9a-z]+)/\\e[5m\1\\e[0m/')" | 513 | echo -e "$(hint=false _print_records | sed -Ee 's/^( *[0-9a-z]+)/\\e[5m\1\\e[0m/')" |
513 | echo | 514 | echo |
@@ -621,18 +622,25 @@ _export_to_github() { | |||
621 | python -mwebbrowser https://github.com/new/import | 622 | python -mwebbrowser https://github.com/new/import |
622 | } | 623 | } |
623 | 624 | ||
625 | _id_to_index() { | ||
626 | while read -r ${INDEX_FORMAT[@]}; do | ||
627 | [[ ! $index =~ s && ${url##*/} == $1 ]] && echo $index | ||
628 | done <$INDEX | ||
629 | } | ||
630 | |||
624 | # Simply commit current changes and push to remote | 631 | # Simply commit current changes and push to remote |
625 | _push_to_remote() { | 632 | _push_to_remote() { |
626 | _set_gist_id $1 || return 1 | 633 | _set_gist_id $1 || return 1 |
627 | cd "$folder/$GIST_ID" | 634 | cd "$folder/$GIST_ID" |
628 | 635 | ||
636 | local index=$(_id_to_index $GIST_ID) | ||
637 | |||
629 | if [[ -n $(git status --short) ]]; then | 638 | if [[ -n $(git status --short) ]]; then |
630 | git add . && git commit -m 'update' | 639 | git add . && git commit -m 'update' |
631 | fi | 640 | fi |
632 | if [[ -n $(git cherry) ]]; then | 641 | if [[ -n $(git cherry) ]]; then |
633 | git push origin master && \ | 642 | git push origin master && \ |
634 | http_method GET "$GITHUB_API/gists/$GIST_ID" | _update_gist $1 | 643 | http_method GET "$GITHUB_API/gists/$GIST_ID" | _update_gist $index |
635 | # FIXME $1 might be empty | ||
636 | fi | 644 | fi |
637 | } | 645 | } |
638 | 646 | ||