diff options
| author | typebrook <typebrook@gmail.com> | 2020-05-18 23:31:46 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-05-18 23:59:44 +0800 |
| commit | 68e9425c9aebc3fd8f75b68adfb4fece95fbbeb8 (patch) | |
| tree | 3b988c6395ae54d998eddd4351b2e451ad221504 | |
| parent | 8f5e430c62a1ac53fbc2693c7e37856a1024e714 (diff) | |
Rename function
| -rwxr-xr-x | gist | 28 |
1 files changed, 14 insertions, 14 deletions
| @@ -295,7 +295,7 @@ _show_hint() { | |||
| 295 | # Display the list of gist, show username for starred gist | 295 | # Display the list of gist, show username for starred gist |
| 296 | # If hint=false, do not print hint to tty. If mark=<pattern>, filter index with regex | 296 | # If hint=false, do not print hint to tty. If mark=<pattern>, filter index with regex |
| 297 | # If display=tag/language, print tags/languages instead or url | 297 | # If display=tag/language, print tags/languages instead or url |
| 298 | _show_list() { | 298 | _print_records() { |
| 299 | if [[ ! -s $INDEX ]]; then | 299 | if [[ ! -s $INDEX ]]; then |
| 300 | echo "Index file is empty, please run commands "$NAME fetch" or "$NAME create"" | 300 | echo "Index file is empty, please run commands "$NAME fetch" or "$NAME create"" |
| 301 | return 0 | 301 | return 0 |
| @@ -338,7 +338,7 @@ _grep_content() { | |||
| 338 | | while read -r "${INDEX_FORMAT[@]}"; do | 338 | | while read -r "${INDEX_FORMAT[@]}"; do |
| 339 | # grep from description | 339 | # grep from description |
| 340 | if grep --color=always -iq "$1" <<<"$description"; then | 340 | if grep --color=always -iq "$1" <<<"$description"; then |
| 341 | hint=false mark="$index " _show_list | 341 | hint=false mark="$index " _print_records |
| 342 | else | 342 | else |
| 343 | local repo=$folder/${url##*/} | 343 | local repo=$folder/${url##*/} |
| 344 | [[ -d $repo ]] && cd $repo || continue | 344 | [[ -d $repo ]] && cd $repo || continue |
| @@ -349,7 +349,7 @@ _grep_content() { | |||
| 349 | local content=$(grep --color=always -EHi -m1 "$1" * 2>/dev/null | head -1) | 349 | local content=$(grep --color=always -EHi -m1 "$1" * 2>/dev/null | head -1) |
| 350 | 350 | ||
| 351 | [[ -n $file && file="$file\n" || -n $content ]] \ | 351 | [[ -n $file && file="$file\n" || -n $content ]] \ |
| 352 | && hint=false mark="$index " _show_list \ | 352 | && hint=false mark="$index " _print_records \ |
| 353 | && echo -e " $file$content" | 353 | && echo -e " $file$content" |
| 354 | fi | 354 | fi |
| 355 | done | 355 | done |
| @@ -442,7 +442,7 @@ _update_gists() { | |||
| 442 | echo $prefix$index $public $extra | 442 | echo $prefix$index $public $extra |
| 443 | done >> $INDEX | 443 | done >> $INDEX |
| 444 | 444 | ||
| 445 | _show_list | 445 | _print_records |
| 446 | [[ $auto_sync != false ]] && (_sync_repos &> /dev/null &) | 446 | [[ $auto_sync != false ]] && (_sync_repos &> /dev/null &) |
| 447 | true | 447 | true |
| 448 | } | 448 | } |
| @@ -508,7 +508,7 @@ _gist_id() { | |||
| 508 | read -r ${INDEX_FORMAT[@]} <<<"$(sed -ne "/^$1 / p" $INDEX)" | 508 | read -r ${INDEX_FORMAT[@]} <<<"$(sed -ne "/^$1 / p" $INDEX)" |
| 509 | GIST_ID=${url##*/} | 509 | GIST_ID=${url##*/} |
| 510 | if [[ -z $GIST_ID || ! $1 =~ [0-9a-z]+ ]]; then | 510 | if [[ -z $GIST_ID || ! $1 =~ [0-9a-z]+ ]]; then |
| 511 | echo -e "$(hint=false _show_list | sed -Ee 's/^( *[0-9a-z]+)/\\e[5m\1\\e[0m/')" | 511 | echo -e "$(hint=false _print_records | sed -Ee 's/^( *[0-9a-z]+)/\\e[5m\1\\e[0m/')" |
| 512 | echo | 512 | echo |
| 513 | echo -e "Invalid index: \e[33m$1\e[0m" | 513 | echo -e "Invalid index: \e[33m$1\e[0m" |
| 514 | echo 'Use the indices blinking instead (like 1 or s1)' | 514 | echo 'Use the indices blinking instead (like 1 or s1)' |
| @@ -710,7 +710,7 @@ _create_gist() { | |||
| 710 | # shellcheck disable=2181 | 710 | # shellcheck disable=2181 |
| 711 | if [[ $? -eq 0 ]]; then | 711 | if [[ $? -eq 0 ]]; then |
| 712 | echo 'Gist is created' | 712 | echo 'Gist is created' |
| 713 | INPUT=$(tail -1 $INDEX | cut -d' ' -f1) hint=false _show_list | 713 | INPUT=$(tail -1 $INDEX | cut -d' ' -f1) hint=false _print_records |
| 714 | else | 714 | else |
| 715 | echo 'Failed to create gist' | 715 | echo 'Failed to create gist' |
| 716 | fi | 716 | fi |
| @@ -734,7 +734,7 @@ _edit_gist() { | |||
| 734 | echo '{' \"description\": \""${DESC//\"/\\\"}"\" '}' > "$http_data" | 734 | echo '{' \"description\": \""${DESC//\"/\\\"}"\" '}' > "$http_data" |
| 735 | 735 | ||
| 736 | http_method PATCH "$GITHUB_API/gists/$GIST_ID" | _update_gist $index \ | 736 | http_method PATCH "$GITHUB_API/gists/$GIST_ID" | _update_gist $index \ |
| 737 | && hint=false mark="$index " _show_list \ | 737 | && hint=false mark="$index " _print_records \ |
| 738 | || echo 'Fail to modify gist description' | 738 | || echo 'Fail to modify gist description' |
| 739 | } | 739 | } |
| 740 | 740 | ||
| @@ -761,7 +761,7 @@ _check_protocol() { | |||
| 761 | _tag_gist() { | 761 | _tag_gist() { |
| 762 | # if no tag is given, show gist list with tags | 762 | # if no tag is given, show gist list with tags |
| 763 | if [[ -z $* ]]; then | 763 | if [[ -z $* ]]; then |
| 764 | display=tag _show_list | 764 | display=tag _print_records |
| 765 | # if user want to change tags of a gist | 765 | # if user want to change tags of a gist |
| 766 | elif _gist_id $1 &>/dev/null; then | 766 | elif _gist_id $1 &>/dev/null; then |
| 767 | _show_detail $1 | sed 3,6d && echo | 767 | _show_detail $1 | sed 3,6d && echo |
| @@ -773,7 +773,7 @@ _tag_gist() { | |||
| 773 | # if user want to filter gists with given tags | 773 | # if user want to filter gists with given tags |
| 774 | else | 774 | else |
| 775 | local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /[[:space:]]|/g; s/\./[^ ]/g' <<<"$@") )" | 775 | local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /[[:space:]]|/g; s/\./[^ ]/g' <<<"$@") )" |
| 776 | hint=false mark=${INPUT:+.} display=tag _show_list | grep --color=always -E "$pattern" | 776 | hint=false mark=${INPUT:+.} display=tag _print_records | grep --color=always -E "$pattern" |
| 777 | fi | 777 | fi |
| 778 | } | 778 | } |
| 779 | 779 | ||
| @@ -824,7 +824,7 @@ _pin_tags() { | |||
| 824 | # show languages of files in gists | 824 | # show languages of files in gists |
| 825 | _gists_with_languages() { | 825 | _gists_with_languages() { |
| 826 | local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /|/g' <<<"$@"))" | 826 | local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /|/g' <<<"$@"))" |
| 827 | display=language _show_list | grep --color=always -Ei "$pattern" | 827 | display=language _print_records | grep --color=always -Ei "$pattern" |
| 828 | } | 828 | } |
| 829 | 829 | ||
| 830 | _gists_with_range() { | 830 | _gists_with_range() { |
| @@ -834,7 +834,7 @@ _gists_with_range() { | |||
| 834 | local maximum=$(sed -Ene "/^${prefix:-[^s]}/ p" $INDEX | wc -l) | 834 | local maximum=$(sed -Ene "/^${prefix:-[^s]}/ p" $INDEX | wc -l) |
| 835 | local range=$(sed -Ee "s/s//g; s/^-/1-/; s/-$/-$maximum/; s/-/ /" <<< "$*") | 835 | local range=$(sed -Ee "s/s//g; s/^-/1-/; s/-$/-$maximum/; s/-/ /" <<< "$*") |
| 836 | INPUT=$(seq $range | sed -e "s/^/p?$prefix/") | 836 | INPUT=$(seq $range | sed -e "s/^/p?$prefix/") |
| 837 | hint=false _show_list | 837 | hint=false _print_records |
| 838 | } | 838 | } |
| 839 | 839 | ||
| 840 | _access_last_index() { | 840 | _access_last_index() { |
| @@ -846,11 +846,11 @@ _apply_config "$@" || exit 1 | |||
| 846 | if [[ $init ]]; then _update_gists; exit 0; fi | 846 | if [[ $init ]]; then _update_gists; exit 0; fi |
| 847 | case "$1" in | 847 | case "$1" in |
| 848 | "") | 848 | "") |
| 849 | _show_list ;; | 849 | _print_records ;; |
| 850 | star | s) | 850 | star | s) |
| 851 | mark=s; _show_list ;; | 851 | mark=s; _print_records ;; |
| 852 | all | a) | 852 | all | a) |
| 853 | mark=.; _show_list ;; | 853 | mark=.; _print_records ;; |
| 854 | fetch | f) | 854 | fetch | f) |
| 855 | [[ $2 =~ ^(s|star)$ ]] && mark=s || mark=[^s] | 855 | [[ $2 =~ ^(s|star)$ ]] && mark=s || mark=[^s] |
| 856 | _update_gists ;; | 856 | _update_gists ;; |