diff options
| author | typebrook <typebrook@gmail.com> | 2020-03-17 22:24:15 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-03-18 11:08:28 +0800 |
| commit | 1c17a1f5eb9ee36524b23b1760f3b18770d3224f (patch) | |
| tree | 3ad073eba18199ea0da0f745d24e2935c00d3891 | |
| parent | e542c1e60a7b6004af1603e770fef77c4d952665 (diff) | |
basic
| -rwxr-xr-x | gist | 42 |
1 files changed, 38 insertions, 4 deletions
| @@ -260,14 +260,18 @@ _check_repo_status() { | |||
| 260 | # If hint=true, print hint to tty. If mark=<pattern>, filter index with regex | 260 | # If hint=true, print hint to tty. If mark=<pattern>, filter index with regex |
| 261 | # TODO color private/starred mark | 261 | # TODO color private/starred mark |
| 262 | _show_list() { | 262 | _show_list() { |
| 263 | if [[ ! -e $INDEX ]]; then | 263 | if [[ -n $1 ]]; then |
| 264 | local input=$1 | ||
| 265 | elif [[ ! -e $INDEX ]]; then | ||
| 264 | echo 'No local file found for last update, please run command:' | 266 | echo 'No local file found for last update, please run command:' |
| 265 | echo ' gist update' | 267 | echo ' gist update' |
| 266 | return 0 | 268 | return 0 |
| 269 | else | ||
| 270 | local input=$INDEX | ||
| 267 | fi | 271 | fi |
| 268 | 272 | ||
| 269 | local prefix=$mark; [[ -z $prefix ]] && prefix=[^s] | 273 | local prefix=$mark; [[ -z $prefix ]] && prefix=[^s] |
| 270 | sed -Ene "/^$prefix/ p" $INDEX \ | 274 | sed -Ene "/^$prefix/ p" $input \ |
| 271 | | while read -r "${INDEX_FORMAT[@]}"; do | 275 | | while read -r "${INDEX_FORMAT[@]}"; do |
| 272 | local repo; repo=$folder/${url##*/} | 276 | local repo; repo=$folder/${url##*/} |
| 273 | local extra; extra=$(_check_repo_status "$repo" "$blob_code") | 277 | local extra; extra=$(_check_repo_status "$repo" "$blob_code") |
| @@ -352,7 +356,7 @@ _fetch_gists() { | |||
| 352 | sed -i'' -Ee "/^$prefix/ d" $INDEX && echo "$result" >> $INDEX | 356 | sed -i'' -Ee "/^$prefix/ d" $INDEX && echo "$result" >> $INDEX |
| 353 | mark=$mark _show_list | 357 | mark=$mark _show_list |
| 354 | 358 | ||
| 355 | [[ $auto_sync == 'true' ]] && (_sync_repos "$1" > /dev/null 2>&1 &) | 359 | [[ $auto_sync == 'true' ]] && (_sync_repos "$1" &> /dev/null &) |
| 356 | true | 360 | true |
| 357 | } | 361 | } |
| 358 | 362 | ||
| @@ -595,11 +599,16 @@ _create_gist() { | |||
| 595 | fi | 599 | fi |
| 596 | } | 600 | } |
| 597 | 601 | ||
| 602 | # get the gist description with a given index | ||
| 603 | _get_desc() { | ||
| 604 | sed -ne "/^$1 / p" $INDEX | cut -d' ' -f${#INDEX_FORMAT[@]}- | ||
| 605 | } | ||
| 606 | |||
| 598 | # Update description of a gist | 607 | # Update description of a gist |
| 599 | _edit_gist() { | 608 | _edit_gist() { |
| 600 | _gist_id "$1" || return 1 | 609 | _gist_id "$1" || return 1 |
| 601 | 610 | ||
| 602 | local prefill=$(sed -ne "/^$1 / p" $INDEX | cut -d' ' -f${#INDEX_FORMAT[@]}-) | 611 | local prefill="$(_get_desc $1)" |
| 603 | if [[ -z $2 ]]; then | 612 | if [[ -z $2 ]]; then |
| 604 | read -e -p 'Edit description: ' -i "$prefill" -r DESC < /dev/tty | 613 | read -e -p 'Edit description: ' -i "$prefill" -r DESC < /dev/tty |
| 605 | else | 614 | else |
| @@ -636,6 +645,28 @@ _check_protocol() { | |||
| 636 | done | 645 | done |
| 637 | } | 646 | } |
| 638 | 647 | ||
| 648 | _tag_gist() { | ||
| 649 | # if user want to change tags of a gist | ||
| 650 | if _gist_id $1 &>/dev/null; then | ||
| 651 | _show_detail $1 | sed 2,5d && echo | ||
| 652 | local desc="$(_get_desc $1)" | ||
| 653 | local hashtags=$(grep -Eo ' #[[:alnum:]\-\_ #]+$' <<<"$desc" | sed -Ee 's/.* [[:alnum:]\-\_]+//g' | xargs) | ||
| 654 | read -e -p 'Edit tags: ' -i "$(tr -d '#' <<<"$hashtags")" -r new_tags < /dev/tty | ||
| 655 | local new_hashtags=$(sed -Ee 's/^/#/; s/ / #/g' <<<"$new_tags") | ||
| 656 | local new_desc=$(sed "s/$hashtags$//; s/ *$/ /" <<<"$desc")${new_hashtags} | ||
| 657 | (_edit_gist $1 "$new_desc" &>/dev/null &) | ||
| 658 | # if user want to filter gists with given tags | ||
| 659 | elif [[ -n $1 ]]; then | ||
| 660 | local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /|/g' <<<"$@"))" | ||
| 661 | sed -En "/$pattern/ p" $INDEX | hint=false _show_list - | ||
| 662 | else | ||
| 663 | while read -r "${INDEX_FORMAT[@]}"; do | ||
| 664 | _hashtags "$description" | tr ' ' '\n' | sed -e '/^$/d' | ||
| 665 | done < $INDEX \ | ||
| 666 | | sort -u | ||
| 667 | fi | ||
| 668 | } | ||
| 669 | |||
| 639 | _apply_config "$@" || exit 1 | 670 | _apply_config "$@" || exit 1 |
| 640 | getConfiguredClient || exit 1 | 671 | getConfiguredClient || exit 1 |
| 641 | if [[ $init ]]; then _fetch_gists; exit 0; fi | 672 | if [[ $init ]]; then _fetch_gists; exit 0; fi |
| @@ -677,6 +708,9 @@ case "$1" in | |||
| 677 | push | p) | 708 | push | p) |
| 678 | shift | 709 | shift |
| 679 | _push_to_remote "$1" ;; | 710 | _push_to_remote "$1" ;; |
| 711 | tag | t) | ||
| 712 | shift | ||
| 713 | _tag_gist "$@" ;; | ||
| 680 | version) | 714 | version) |
| 681 | echo "Version $currentVersion" ;; | 715 | echo "Version $currentVersion" ;; |
| 682 | update) | 716 | update) |