aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xgist61
1 files changed, 42 insertions, 19 deletions
diff --git a/gist b/gist
index e3907b7..90181b4 100755
--- a/gist
+++ b/gist
@@ -292,8 +292,14 @@ _show_list() {
292 echo -e "$raw_output" | cut -c -$(( $(tput cols) +decorator )) 292 echo -e "$raw_output" | cut -c -$(( $(tput cols) +decorator ))
293 done 293 done
294 294
295 [[ $hint == 'true' ]] && echo -e '\nrun "gist fetch" to update gists or "gist help" for more details' > /dev/tty \ 295 if [[ $tag == 'true' && -n $pin ]]; then
296 || return 0 296 local pinned_tags=( $pin )
297 echo
298 echo Pinned tags: ${pinned_tags[@]/#/#}
299 elif [[ $hint == 'true' ]]; then
300 echo
301 echo 'run "gist fetch" to update gists or "gist help" for more details' > /dev/tty
302 fi
297} 303}
298 304
299# Grep description, filename or file content with a given pattern 305# Grep description, filename or file content with a given pattern
@@ -674,31 +680,48 @@ _tag_gist() {
674 fi 680 fi
675} 681}
676 682
683# show all tags and pinned tags
677_show_tags() { 684_show_tags() {
678 while read -r "${INDEX_FORMAT[@]}"; do 685 local pinned_tags=( $pin )
679 _hashtags "$description" | tr ' ' '\n' | sed -e '/^$/d' 686 local tags=$(while read -r "${INDEX_FORMAT[@]}"; do
680 done < $INDEX \ 687 _hashtags "$description" | tr ' ' '\n' | sed -e '/^$/d'
681 | sort -u 688 done < $INDEX | sort -u)
689
690 for prefix in {0..9} {a..z} {A-Z} [^0-9a-zA-Z]; do
691 local line=$(echo $tags | grep -Eo "#$prefix[^ ]+" | tr '\n' ' ')
692 [[ -z $line ]] && continue
693
694 # add color to pinned tags
695 pattern='('$(sed 's/ /|/g' <<<"${pinned_tags[@]/#/#}")')'
696 echo -e "$(sed -E -e "s/$pattern/\\\e[33m\1\\\e[0m/g" <<<"$line")"
697 done
682 698
683 tags=( $pin )
684 echo 699 echo
685 echo Pinned tags: ${tags[@]/#/#} 700 if [[ ${#pinned_tags} == 0 ]]; then
701 echo 'Run "gist pin <tag1> <tag2>..." to pin tags'
702 else
703 echo Pinned tags: ${pinned_tags[@]/#/#}
704 fi
686} 705}
687 706
688# pin/unpin tags 707# pin/unpin tags
689_pin_tags() { 708_pin_tags() {
690 local new_pinned=( $(echo $pin $* | tr ' ' '\n' | sort | uniq -u | xargs) ) 709 # if no arguments, print gists with pinned tags
691 for tag in ${new_pinned[@]}; do 710 if [[ -z $* && -n $pin ]]; then
692 if _gist_id $tag &> /dev/null; then 711 hint=false _tag_gist $pin
693 echo Invalid tag: $tag 712 else
694 return 1 713 local new_pinned=( $(echo $pin $* | tr ' ' '\n' | sort | uniq -u | xargs) )
695 fi 714 for tag in ${new_pinned[@]}; do
696 done || exit 1 715 if [[ $tag =~ [p]*[0-9]+ ]]; then
716 echo Invalid tag: $tag
717 return 1
718 fi
719 done || exit 1
697 720
698 hint=false _tag_gist ${new_pinned[@]} 721 pin="${new_pinned[@]}"
699 echo > /dev/tty 722 _show_tags
700 echo Pinned tags: ${new_pinned[@]/#/#} > /dev/tty 723 sed -i'' -e "/^pin=/ d" "$CONFIG" && echo pin=\'"${new_pinned[@]}"\' >> "$CONFIG"
701 sed -i'' -e "/^pin=/ d" "$CONFIG" && echo pin=\'"${new_pinned[@]}"\' >> "$CONFIG" 724 fi
702} 725}
703 726
704_apply_config "$@" || exit 1 727_apply_config "$@" || exit 1