From 68e9425c9aebc3fd8f75b68adfb4fece95fbbeb8 Mon Sep 17 00:00:00 2001 From: typebrook Date: Mon, 18 May 2020 23:31:46 +0800 Subject: Rename function --- gist | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/gist b/gist index cb8d5de..035edce 100755 --- a/gist +++ b/gist @@ -295,7 +295,7 @@ _show_hint() { # Display the list of gist, show username for starred gist # If hint=false, do not print hint to tty. If mark=, filter index with regex # If display=tag/language, print tags/languages instead or url -_show_list() { +_print_records() { if [[ ! -s $INDEX ]]; then echo "Index file is empty, please run commands "$NAME fetch" or "$NAME create"" return 0 @@ -338,7 +338,7 @@ _grep_content() { | while read -r "${INDEX_FORMAT[@]}"; do # grep from description if grep --color=always -iq "$1" <<<"$description"; then - hint=false mark="$index " _show_list + hint=false mark="$index " _print_records else local repo=$folder/${url##*/} [[ -d $repo ]] && cd $repo || continue @@ -349,7 +349,7 @@ _grep_content() { local content=$(grep --color=always -EHi -m1 "$1" * 2>/dev/null | head -1) [[ -n $file && file="$file\n" || -n $content ]] \ - && hint=false mark="$index " _show_list \ + && hint=false mark="$index " _print_records \ && echo -e " $file$content" fi done @@ -442,7 +442,7 @@ _update_gists() { echo $prefix$index $public $extra done >> $INDEX - _show_list + _print_records [[ $auto_sync != false ]] && (_sync_repos &> /dev/null &) true } @@ -508,7 +508,7 @@ _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 _show_list | sed -Ee 's/^( *[0-9a-z]+)/\\e[5m\1\\e[0m/')" + echo -e "$(hint=false _print_records | sed -Ee 's/^( *[0-9a-z]+)/\\e[5m\1\\e[0m/')" echo echo -e "Invalid index: \e[33m$1\e[0m" echo 'Use the indices blinking instead (like 1 or s1)' @@ -710,7 +710,7 @@ _create_gist() { # shellcheck disable=2181 if [[ $? -eq 0 ]]; then echo 'Gist is created' - INPUT=$(tail -1 $INDEX | cut -d' ' -f1) hint=false _show_list + INPUT=$(tail -1 $INDEX | cut -d' ' -f1) hint=false _print_records else echo 'Failed to create gist' fi @@ -734,7 +734,7 @@ _edit_gist() { echo '{' \"description\": \""${DESC//\"/\\\"}"\" '}' > "$http_data" http_method PATCH "$GITHUB_API/gists/$GIST_ID" | _update_gist $index \ - && hint=false mark="$index " _show_list \ + && hint=false mark="$index " _print_records \ || echo 'Fail to modify gist description' } @@ -761,7 +761,7 @@ _check_protocol() { _tag_gist() { # if no tag is given, show gist list with tags if [[ -z $* ]]; then - display=tag _show_list + display=tag _print_records # if user want to change tags of a gist elif _gist_id $1 &>/dev/null; then _show_detail $1 | sed 3,6d && echo @@ -773,7 +773,7 @@ _tag_gist() { # if user want to filter gists with given tags else local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /[[:space:]]|/g; s/\./[^ ]/g' <<<"$@") )" - hint=false mark=${INPUT:+.} display=tag _show_list | grep --color=always -E "$pattern" + hint=false mark=${INPUT:+.} display=tag _print_records | grep --color=always -E "$pattern" fi } @@ -824,7 +824,7 @@ _pin_tags() { # show languages of files in gists _gists_with_languages() { local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /|/g' <<<"$@"))" - display=language _show_list | grep --color=always -Ei "$pattern" + display=language _print_records | grep --color=always -Ei "$pattern" } _gists_with_range() { @@ -834,7 +834,7 @@ _gists_with_range() { local maximum=$(sed -Ene "/^${prefix:-[^s]}/ p" $INDEX | wc -l) local range=$(sed -Ee "s/s//g; s/^-/1-/; s/-$/-$maximum/; s/-/ /" <<< "$*") INPUT=$(seq $range | sed -e "s/^/p?$prefix/") - hint=false _show_list + hint=false _print_records } _access_last_index() { @@ -846,11 +846,11 @@ _apply_config "$@" || exit 1 if [[ $init ]]; then _update_gists; exit 0; fi case "$1" in "") - _show_list ;; + _print_records ;; star | s) - mark=s; _show_list ;; + mark=s; _print_records ;; all | a) - mark=.; _show_list ;; + mark=.; _print_records ;; fetch | f) [[ $2 =~ ^(s|star)$ ]] && mark=s || mark=[^s] _update_gists ;; -- cgit v1.2.3-70-g09d2