diff options
author | typebrook <typebrook@gmail.com> | 2020-03-20 20:11:35 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-03-20 20:11:35 +0800 |
commit | beead39ccad50cbaa8f7f82a0d4b8e12329d71ff (patch) | |
tree | b4bed7a266525f9c20ab2fe54bd1f4e7f865b2d4 | |
parent | 994b4f984a0c06a1e35a65bb953afc4220cd97f3 (diff) |
Add color for pinned tags in 'gist tag'
-rwxr-xr-x | gist | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -39,7 +39,6 @@ | |||
39 | # Since now a gist is a local cloned repo | 39 | # Since now a gist is a local cloned repo |
40 | # It is your business to do git commit and git push | 40 | # It is your business to do git commit and git push |
41 | 41 | ||
42 | # TODO color pinned tags | ||
43 | # TODO README/helper message about tag and default action ${SHELL:-bash} | 42 | # TODO README/helper message about tag and default action ${SHELL:-bash} |
44 | # TODO codebase statistics, like C++ or something | 43 | # TODO codebase statistics, like C++ or something |
45 | # TODO migrate to gh-page, with install.sh and check_md5 in README | 44 | # TODO migrate to gh-page, with install.sh and check_md5 in README |
@@ -239,6 +238,12 @@ _hashtags() { | |||
239 | grep -Eo " #[$TAG_CHAR #]+$" <<<"$1" | sed -Ee "s/.* [$TAG_CHAR]+//g" | xargs | 238 | grep -Eo " #[$TAG_CHAR #]+$" <<<"$1" | sed -Ee "s/.* [$TAG_CHAR]+//g" | xargs |
240 | } | 239 | } |
241 | 240 | ||
241 | _color_pinned_tags() { | ||
242 | local pinned_tags=( $pin ) | ||
243 | pattern='('$(sed -E 's/ /[[:space:]]|/g; s/$/[[:space:]]/' <<<"${pinned_tags[@]/#/#}")')' | ||
244 | sed -E -e "s/$pattern/\\\e[33m\1\\\e[0m/g" <<<"$1 " | ||
245 | } | ||
246 | |||
242 | # Return git status of a given repo | 247 | # Return git status of a given repo |
243 | _check_repo_status() { | 248 | _check_repo_status() { |
244 | if [[ ! -d $1 ]]; then | 249 | if [[ ! -d $1 ]]; then |
@@ -285,6 +290,7 @@ _show_list() { | |||
285 | [[ $tag == 'true' ]] && url="$hashtags" && local width=45 && align=' ' | 290 | [[ $tag == 'true' ]] && url="$hashtags" && local width=45 && align=' ' |
286 | 291 | ||
287 | raw_output="$(printf "% 3s" "$index") $(printf "%${align:--}${width:-56}s" "$url") $extra $description" | 292 | raw_output="$(printf "% 3s" "$index") $(printf "%${align:--}${width:-56}s" "$url") $extra $description" |
293 | [[ -n $pin ]] && raw_output="$(_color_pinned_tags "$raw_output")" | ||
288 | decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 )) | 294 | decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 )) |
289 | echo -e "$raw_output" | cut -c -$(( $(tput cols) +decorator )) | 295 | echo -e "$raw_output" | cut -c -$(( $(tput cols) +decorator )) |
290 | done | 296 | done |
@@ -670,7 +676,7 @@ _tag_gist() { | |||
670 | (_edit_gist $1 "$new_desc" &>/dev/null &) | 676 | (_edit_gist $1 "$new_desc" &>/dev/null &) |
671 | # if user want to filter gists with given tags | 677 | # if user want to filter gists with given tags |
672 | elif [[ -n $1 ]]; then | 678 | elif [[ -n $1 ]]; then |
673 | local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /|/g' <<<"$@"))" | 679 | local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /[[:space:]]|/g; s/$/[[:space:]]/' <<<"$@"))" |
674 | sed -En "/$pattern/ p" $INDEX | hint=false tag=true _show_list - | 680 | sed -En "/$pattern/ p" $INDEX | hint=false tag=true _show_list - |
675 | else | 681 | else |
676 | tag=true _show_list | 682 | tag=true _show_list |
@@ -689,8 +695,7 @@ _show_tags() { | |||
689 | [[ -z $line ]] && continue | 695 | [[ -z $line ]] && continue |
690 | 696 | ||
691 | # add color to pinned tags | 697 | # add color to pinned tags |
692 | pattern='('$(sed 's/ /|/g' <<<"${pinned_tags[@]/#/#}")')' | 698 | echo -e "$(_color_pinned_tags "$line")" |
693 | echo -e "$(sed -E -e "s/$pattern/\\\e[33m\1\\\e[0m/g" <<<"$line")" | ||
694 | done | 699 | done |
695 | 700 | ||
696 | echo | 701 | echo |