diff options
author | typebrook <typebrook@gmail.com> | 2020-03-17 17:32:28 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-03-17 18:12:08 +0800 |
commit | d80ef6ec5399d6d7bac0a0cdff9bd20a23e6e80f (patch) | |
tree | 26f86c0ca2a71cdf83b4ff444ba10fcc61bc7eb4 | |
parent | d86d25e22dd265cbe29ffdaf01e3c1d09bd79386 (diff) |
Refactor code about INDEX file format
Refactor code to reduce potential code changes when INDEX file format
changes
-rwxr-xr-x | gist | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -486,17 +486,18 @@ for comment in raw: | |||
486 | # TODO add parameter --comment to fetch comments | 486 | # TODO add parameter --comment to fetch comments |
487 | _show_detail() { | 487 | _show_detail() { |
488 | _gist_id "$1" || return 1 | 488 | _gist_id "$1" || return 1 |
489 | record=$(sed -ne "/^$1 / p" $INDEX) | 489 | sed -n "/^$1 / p" $INDEX \ |
490 | echo description: $(echo $record | cut -d' ' -f9-) | 490 | | while read -r ${INDEX_FORMAT[@]}; do |
491 | echo site: https://gist.github.com/$GIST_ID | 491 | echo description: $description |
492 | echo API: https://api.github.com/gists/$GIST_ID | 492 | echo site: https://gist.github.com/$GIST_ID |
493 | echo created_at: $(echo $record | cut -d' ' -f7) | 493 | echo API: https://api.github.com/gists/$GIST_ID |
494 | echo updated_at: $(echo $record | cut -d' ' -f8) | 494 | echo created_at: $created_at |
495 | repo=$folder/$GIST_ID | 495 | echo updated_at: $updated_at |
496 | if [[ -d $repo ]]; then | 496 | repo=$folder/$GIST_ID |
497 | echo files: | 497 | if [[ -d $repo ]]; then |
498 | ls $repo | sed -e 's/^/ /' | 498 | echo files:; ls $repo | sed -e 's/^/ /' |
499 | fi | 499 | fi |
500 | done | ||
500 | } | 501 | } |
501 | 502 | ||
502 | # Open Github repository import page | 503 | # Open Github repository import page |
@@ -593,7 +594,7 @@ _create_gist() { | |||
593 | _edit_gist() { | 594 | _edit_gist() { |
594 | _gist_id "$1" || return 1 | 595 | _gist_id "$1" || return 1 |
595 | 596 | ||
596 | local prefill=$(sed -ne "/^$1 / p" $INDEX | cut -d' ' -f9-) | 597 | local prefill=$(sed -ne "/^$1 / p" $INDEX | cut -d' ' -f${#INDEX_FORMAT[@]}-) |
597 | if [[ -z $2 ]]; then | 598 | if [[ -z $2 ]]; then |
598 | read -e -p 'Edit description: ' -i "$prefill" -r DESC < /dev/tty | 599 | read -e -p 'Edit description: ' -i "$prefill" -r DESC < /dev/tty |
599 | else | 600 | else |