From 9fe26b4cfc57a691603b8c790b2daf15e8b3f738 Mon Sep 17 00:00:00 2001 From: typebrook Date: Wed, 18 Mar 2020 15:34:10 +0800 Subject: Modify sub-commands for tags - 'gist tag' to show gist list without url but tags insdead - 'gist tags' to list existing tags --- gist | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/gist b/gist index 1719520..b3b0756 100755 --- a/gist +++ b/gist @@ -283,9 +283,11 @@ _show_list() { local extra; extra=$(_check_repo_status "$repo" "$blob_code") [[ -z $extra ]] && extra="$file_num $comment_num" [[ $index =~ ^s ]] && extra=$(printf "%-12s" $author)${extra} - description=$(echo $description | sed -E -e 's/\[(.+)\]/\\e[33m[\1]\\e[0m/') + hashtags=$(_hashtags "$description") + description=$(sed -E -e 's/\[(.+)\]/\\e[33m[\1]\\e[0m/' <<<"$description" | sed "s/ $hashtags$//") + [[ $tag == 'true' ]] && url="$hashtags" && local width=45 - echo -e "$(printf "% 3s" "$index") $(printf "%-56s" "$url") $extra $description" \ + echo -e "$(printf "% 3s" "$index") $(printf "%-${width:-56}s" "$url") $extra $description" \ | cut -c -"$(tput cols)" done @@ -668,13 +670,17 @@ _tag_gist() { local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /|/g' <<<"$@"))" sed -En "/$pattern/ p" $INDEX | hint=false _show_list - else - while read -r "${INDEX_FORMAT[@]}"; do - _hashtags "$description" | tr ' ' '\n' | sed -e '/^$/d' - done < $INDEX \ - | sort -u + tag=true _show_list fi } +_show_tags() { + while read -r "${INDEX_FORMAT[@]}"; do + _hashtags "$description" | tr ' ' '\n' | sed -e '/^$/d' + done < $INDEX \ + | sort -u +} + _apply_config "$@" || exit 1 getConfiguredClient || exit 1 if [[ $init ]]; then _fetch_gists; exit 0; fi @@ -719,6 +725,8 @@ case "$1" in tag | t) shift _tag_gist "$@" ;; + tags) + _show_tags ;; version) echo "Version $currentVersion" ;; update) -- cgit v1.2.3-70-g09d2