diff options
| author | typebrook <typebrook@gmail.com> | 2020-05-14 17:20:39 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-05-14 17:21:51 +0800 |
| commit | d3a1794c6cb2b8385171ef12deac1018db28f0d5 (patch) | |
| tree | aa2693b111f1d40badc28f4b8d68619fa19b80e9 | |
| parent | 8124b6fd049d1b7fa19113fd0b117827ef6a00d8 (diff) | |
Refactor _show_list()
| -rwxr-xr-x | gist | 33 |
1 files changed, 17 insertions, 16 deletions
| @@ -326,6 +326,19 @@ _index_pattern() { | |||
| 326 | fi | 326 | fi |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | _show_hint() { | ||
| 330 | if [[ $display == 'tag' && -n $pin ]]; then | ||
| 331 | local pinned_tags=( $pin ) | ||
| 332 | echo > /dev/tty | ||
| 333 | echo Pinned tags: "${pinned_tags[*]/#/#} " > /dev/tty | ||
| 334 | elif [[ $hint != 'false' ]]; then | ||
| 335 | local mtime="$(mtime $INDEX | cut -d'.' -f1)" | ||
| 336 | echo > /dev/tty | ||
| 337 | echo "Last updated at $mtime" > /dev/tty | ||
| 338 | echo "Run \"$NAME fetch\" to keep gists up to date, or \"$NAME help\" for more details" > /dev/tty | ||
| 339 | fi | ||
| 340 | } | ||
| 341 | |||
| 329 | # Display the list of gist, show username for starred gist | 342 | # Display the list of gist, show username for starred gist |
| 330 | # If hint=false, do not print hint to tty. If mark=<pattern>, filter index with regex | 343 | # If hint=false, do not print hint to tty. If mark=<pattern>, filter index with regex |
| 331 | # If display=tag/language, print tags/languages instead or url | 344 | # If display=tag/language, print tags/languages instead or url |
| @@ -347,29 +360,17 @@ _show_list() { | |||
| 347 | local width=45; local align=' '; | 360 | local width=45; local align=' '; |
| 348 | fi | 361 | fi |
| 349 | 362 | ||
| 350 | local status='' | ||
| 351 | status=$(_check_repo_status "$folder/${url##*/}" "$blob_code") | ||
| 352 | status="${status:+${status} }" | ||
| 353 | local extra="$(printf "%-4s" "$file_num $comment_num")" | 363 | local extra="$(printf "%-4s" "$file_num $comment_num")" |
| 354 | 364 | local status=''; status=$(_check_repo_status "$folder/${url##*/}" "$blob_code") | |
| 355 | [[ $index =~ ^s ]] && description="$(printf "%-12s" [${author}]) ${description}" | 365 | [[ $index =~ ^s ]] && description="$(printf "%-12s" [${author}]) ${description}" |
| 356 | 366 | ||
| 357 | raw_output="$(printf "%-3s" "$index") $(printf "%${align:--}${width:-56}s" "$message") $extra $status$(_color_description_title "$description")" | 367 | raw_output="$(printf "%-3s" "$index") $(printf "%${align:--}${width:-56}s" "$message") $extra ${status:+${status} }$(_color_description_title "$description")" |
| 358 | [[ -n $pin ]] && raw_output="$(_color_pinned_tags "$raw_output")" | 368 | [[ -n $pin ]] && raw_output="$(_color_pinned_tags "$raw_output")" |
| 359 | decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 )) | 369 | decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 )) |
| 360 | echo -e "$raw_output" | cut -c -$(( $(tput cols) +decorator )) | 370 | echo -e "$raw_output" | cut -c -$(( $(tput cols) +decorator )) |
| 361 | done | 371 | done |
| 362 | 372 | ||
| 363 | if [[ $display == 'tag' && -n $pin ]]; then | 373 | [[ -z $INPUT ]] && _show_hint || true |
| 364 | local pinned_tags=( $pin ) | ||
| 365 | echo > /dev/tty | ||
| 366 | echo Pinned tags: "${pinned_tags[*]/#/#} " > /dev/tty | ||
| 367 | elif [[ -z $INPUT && $hint != 'false' ]]; then | ||
| 368 | local mtime="$(mtime $INDEX | cut -d'.' -f1)" | ||
| 369 | echo > /dev/tty | ||
| 370 | echo "Last updated at $mtime" > /dev/tty | ||
| 371 | echo "Run \"$NAME fetch\" to keep gists up to date, or \"$NAME help\" for more details" > /dev/tty | ||
| 372 | fi | ||
| 373 | } | 374 | } |
| 374 | 375 | ||
| 375 | # Grep description, filename or file content with a given pattern | 376 | # Grep description, filename or file content with a given pattern |
| @@ -834,7 +835,7 @@ _pin_tags() { | |||
| 834 | # show languages of files in gists | 835 | # show languages of files in gists |
| 835 | _gists_with_languages() { | 836 | _gists_with_languages() { |
| 836 | local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /|/g' <<<"$@"))" | 837 | local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /|/g' <<<"$@"))" |
| 837 | hint=false display=language _show_list | grep --color=always -Ei "$pattern" | 838 | display=language _show_list | grep --color=always -Ei "$pattern" |
| 838 | } | 839 | } |
| 839 | 840 | ||
| 840 | _gists_with_range() { | 841 | _gists_with_range() { |