aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-03-22 14:16:28 +0800
committertypebrook <typebrook@gmail.com>2020-03-22 14:16:35 +0800
commit3c2da44425b822dd6a0af33d50fabaacc62bab48 (patch)
tree48538537ff7b02fbf4413474e171190279f70139
parent354616f8a6e82189bc84e6fc06234426ed3482fc (diff)
Refactor code for tag condition, speed up 'gist tag' !
-rwxr-xr-xgist8
1 files changed, 4 insertions, 4 deletions
diff --git a/gist b/gist
index 378b1e6..5700358 100755
--- a/gist
+++ b/gist
@@ -684,7 +684,9 @@ _check_protocol() {
684 684
685_tag_gist() { 685_tag_gist() {
686 # if user want to change tags of a gist 686 # if user want to change tags of a gist
687 if _gist_id $1 &>/dev/null; then 687 if [[ -z $@ ]]; then
688 tag=true _show_list
689 elif _gist_id $1 &>/dev/null; then
688 _show_detail $1 | sed 3,6d && echo 690 _show_detail $1 | sed 3,6d && echo
689 local desc="$(_get_desc $1)" 691 local desc="$(_get_desc $1)"
690 local hashtags=$(_hashtags "$desc") 692 local hashtags=$(_hashtags "$desc")
@@ -693,11 +695,9 @@ _tag_gist() {
693 local new_desc=$(sed "s/$hashtags$//; s/ *$/ /" <<<"$desc")${new_hashtags} 695 local new_desc=$(sed "s/$hashtags$//; s/ *$/ /" <<<"$desc")${new_hashtags}
694 (_edit_gist $1 "$new_desc" &>/dev/null &) 696 (_edit_gist $1 "$new_desc" &>/dev/null &)
695 # if user want to filter gists with given tags 697 # if user want to filter gists with given tags
696 elif [[ -n $1 ]]; then 698 else
697 local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /[[:space:]]|/g' <<<"$@") )" 699 local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /[[:space:]]|/g' <<<"$@") )"
698 hint=false tag=true _show_list | grep --color=always -E "$pattern" 700 hint=false tag=true _show_list | grep --color=always -E "$pattern"
699 else
700 tag=true tag=true _show_list
701 fi 701 fi
702} 702}
703 703