diff options
author | typebrook <typebrook@gmail.com> | 2020-05-18 21:50:29 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-05-18 23:59:44 +0800 |
commit | bb4bcf9dd92bfba5a016f0cc0ca6329598dbdd01 (patch) | |
tree | 83766f97a5050f885890c07de7556f73fedab8c8 | |
parent | 114be765b63d6c9c0fb8f59e82a39800795cfd5d (diff) |
Refactor color functions
-rwxr-xr-x | gist | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -237,14 +237,12 @@ _trailing_hashtags() { | |||
237 | grep -Eo " #[$TAG_CHAR #]+$" <<<"$1" | sed -Ee "s/.* [$TAG_CHAR]+//g" | 237 | grep -Eo " #[$TAG_CHAR #]+$" <<<"$1" | sed -Ee "s/.* [$TAG_CHAR]+//g" |
238 | } | 238 | } |
239 | 239 | ||
240 | _color_pinned_tags() { | 240 | _color_pattern() { |
241 | local pinned_tags=( $pin ) | 241 | sed -Ee "s/$1/\\\e[33m\1\\\e[0m/g" |
242 | pattern='('$(sed -E 's/ /[[:space:]]|/g; s/\./[^ ]/g; s/$/[[:space:]]/' <<<"${pinned_tags[@]/#/#}")')' | ||
243 | sed -E -e "s/$pattern/\\\e[33m\1\\\e[0m/g" <<<"$1 " | ||
244 | } | 242 | } |
245 | 243 | ||
246 | _color_description_title() { | 244 | _pattern_pinned_tags() { |
247 | sed -E -e 's/^\[(.+)\]/\\e[33m[\1]\\e[0m/' <<<"$1" | 245 | echo '('$(sed -E 's/ /[[:space:]]|/g; s/\./[^ ]/g; s/$/[[:space:]]/' <<<"$@")')' |
248 | } | 246 | } |
249 | 247 | ||
250 | # Return git status of a given repo | 248 | # Return git status of a given repo |
@@ -320,8 +318,11 @@ _show_list() { | |||
320 | local status=''; status=$(_check_repo_status "$folder/${url##*/}" "$blob_code") | 318 | local status=''; status=$(_check_repo_status "$folder/${url##*/}" "$blob_code") |
321 | [[ $index =~ ^s ]] && description="$(printf "%-12s" [${author}]) ${description}" | 319 | [[ $index =~ ^s ]] && description="$(printf "%-12s" [${author}]) ${description}" |
322 | 320 | ||
323 | raw_output="$(printf "%-3s" "$index") $(printf "%${align:--}${width:-56}s" "$message") $extra ${status:+${status} }$(_color_description_title "$description")" | 321 | raw_output="$(printf "%-3s" "$index") $(printf "%${align:--}${width:-56}s" "$message") $extra ${status:+${status} }$(_color_pattern '^(\[.+\])' <<<"$description")" |
324 | [[ -n $pin ]] && raw_output="$(_color_pinned_tags "$raw_output")" | 322 | if [[ -n $pin && $display == 'tag' ]]; then |
323 | local pinned_tags=($pin); local pattern="$(_pattern_pinned_tags ${pinned_tags[@]/#/#})" | ||
324 | raw_output="$(_color_pattern "$pattern" <<<"$raw_output")" | ||
325 | fi | ||
325 | decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 )) | 326 | decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 )) |
326 | echo -e "$raw_output" | cut -c -$(( $(tput cols) +decorator )) | 327 | echo -e "$raw_output" | cut -c -$(( $(tput cols) +decorator )) |
327 | done | 328 | done |
@@ -601,7 +602,7 @@ _show_detail() { | |||
601 | 602 | ||
602 | sed -En -e "/[^ ]+ [^ ]+$GIST_ID / {p; q}" $INDEX \ | 603 | sed -En -e "/[^ ]+ [^ ]+$GIST_ID / {p; q}" $INDEX \ |
603 | | while read -r "${INDEX_FORMAT[@]}"; do | 604 | | while read -r "${INDEX_FORMAT[@]}"; do |
604 | echo -e desc: $(_color_description_title "$description") | 605 | echo -e desc: $(_color_pattern '^(\[.+\])' <<<"$description") |
605 | echo -e tags: ${tags_string//,/ } | 606 | echo -e tags: ${tags_string//,/ } |
606 | echo -e site: https://gist.github.com/$GIST_ID | 607 | echo -e site: https://gist.github.com/$GIST_ID |
607 | echo -e API : https://api.github.com/gists/$GIST_ID | 608 | echo -e API : https://api.github.com/gists/$GIST_ID |
@@ -780,6 +781,7 @@ _tag_gist() { | |||
780 | # show all tags and pinned tags | 781 | # show all tags and pinned tags |
781 | _show_tags() { | 782 | _show_tags() { |
782 | local pinned_tags=( $pin ) | 783 | local pinned_tags=( $pin ) |
784 | local pattern=$(_pattern_pinned_tags "${pinned_tags[@]/#/#}") | ||
783 | local tags=$(while read -r "${INDEX_FORMAT[@]}"; do | 785 | local tags=$(while read -r "${INDEX_FORMAT[@]}"; do |
784 | echo ${tags_string//,/ } | 786 | echo ${tags_string//,/ } |
785 | done < $INDEX | tr ' ' '\n' | sed -e '/^$/d' | sort -u) | 787 | done < $INDEX | tr ' ' '\n' | sed -e '/^$/d' | sort -u) |
@@ -789,7 +791,7 @@ _show_tags() { | |||
789 | [[ -z $line ]] && continue | 791 | [[ -z $line ]] && continue |
790 | 792 | ||
791 | # add color to pinned tags | 793 | # add color to pinned tags |
792 | echo -e "$(_color_pinned_tags "$line")" | 794 | echo -e $(_color_pattern "$pattern" <<<"$line") |
793 | done | 795 | done |
794 | 796 | ||
795 | echo | 797 | echo |