aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-03-27 23:21:59 +0800
committertypebrook <typebrook@gmail.com>2020-03-29 13:59:13 +0800
commit328cbc344025ce95d83f5f2f76698f911d381f6a (patch)
treea7852819b388129e0ad2c7c9466f1d2b067cf1ab
parentb4ec421d89f8d4eeaa4ad278d93ab01cec0a77cd (diff)
Add subcommand 'gist lan'
-rwxr-xr-xgist31
1 files changed, 24 insertions, 7 deletions
diff --git a/gist b/gist
index cd16ae7..c93bb13 100755
--- a/gist
+++ b/gist
@@ -22,6 +22,8 @@
22# tags, tt List all tags and pinned tags 22# tags, tt List all tags and pinned tags
23# pin, p <TAG>... Pin/Unpin tags 23# pin, p <TAG>... Pin/Unpin tags
24# pin, p Grep gists with pinned tags 24# pin, p Grep gists with pinned tags
25# lan, l <PATTERN>... Grep gists with languages
26# lan, l List gist with languages of files
25# detail, d <INDEX> Show the detail of a gist 27# detail, d <INDEX> Show the detail of a gist
26# edit, e <INDEX> ["NEW_DESCRIPTRION"] Edit a gist's description 28# edit, e <INDEX> ["NEW_DESCRIPTRION"] Edit a gist's description
27# delete, D <INDEX>... [--force] Delete gists by given indices 29# delete, D <INDEX>... [--force] Delete gists by given indices
@@ -45,7 +47,6 @@
45# Since now a gist is a local cloned repo 47# Since now a gist is a local cloned repo
46# It is your business to do git commit and git push 48# It is your business to do git commit and git push
47 49
48# TODO support file type from github API, like 'gist code'
49# TODO README/helper message about tag and default action ${SHELL:-bash} 50# TODO README/helper message about tag and default action ${SHELL:-bash}
50# TODO codebase statistics, like C++ or something 51# TODO codebase statistics, like C++ or something
51# TODO migrate to gh-page, with install.sh and check_md5 in README 52# TODO migrate to gh-page, with install.sh and check_md5 in README
@@ -283,7 +284,7 @@ _index_pattern() {
283 284
284# Display the list of gist, show username for starred gist 285# Display the list of gist, show username for starred gist
285# If hint=true, print hint to tty. If mark=<pattern>, filter index with regex 286# If hint=true, print hint to tty. If mark=<pattern>, filter index with regex
286# If tag=true, print tags instead or url 287# If display=tag, print tags instead or url
287# TODO color private/starred mark 288# TODO color private/starred mark
288_show_list() { 289_show_list() {
289 if [[ ! -s $INDEX ]]; then 290 if [[ ! -s $INDEX ]]; then
@@ -298,15 +299,22 @@ _show_list() {
298 local hashtags=$(_hashtags "$description") 299 local hashtags=$(_hashtags "$description")
299 [[ $index =~ ^s ]] && description="$(printf "%-12s" [${author}]) ${description}" 300 [[ $index =~ ^s ]] && description="$(printf "%-12s" [${author}]) ${description}"
300 description=$(sed -E -e 's/^\[(.+)\]/\\e[33m[\1]\\e[0m/' <<<"$description" | sed "s/ $hashtags$//") 301 description=$(sed -E -e 's/^\[(.+)\]/\\e[33m[\1]\\e[0m/' <<<"$description" | sed "s/ $hashtags$//")
301 [[ $tag == 'true' ]] && { url="$hashtags"; local width=45; align=' '; extra=''; }
302 302
303 raw_output="$(printf "%-3s" "$index") $(printf "%${align:--}${width:-56}s" "$url") $extra $description" 303 local message=$url
304 if [[ $display == 'tag' ]]; then
305 message="$hashtags"; local width=45; local align=' '; extra='';
306 elif [[ $display == 'language' ]]; then
307 message="$(tr ',' '\n' <<< $file_array | sed -Ee 's/.+@/#/' | uniq | xargs)"
308 local width=45; local align=' '; extra='';
309 fi
310
311 raw_output="$(printf "%-3s" "$index") $(printf "%${align:--}${width:-56}s" "$message") $extra $description"
304 [[ -n $pin ]] && raw_output="$(_color_pinned_tags "$raw_output")" 312 [[ -n $pin ]] && raw_output="$(_color_pinned_tags "$raw_output")"
305 decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 )) 313 decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 ))
306 echo -e "$raw_output" | cut -c -$(( $(tput cols) +decorator )) 314 echo -e "$raw_output" | cut -c -$(( $(tput cols) +decorator ))
307 done 315 done
308 316
309 if [[ $tag == 'true' && -n $pin ]]; then 317 if [[ $display == 'tag' && -n $pin ]]; then
310 local pinned_tags=( $pin ) 318 local pinned_tags=( $pin )
311 echo 319 echo
312 echo Pinned tags: "${pinned_tags[*]/#/#} " 320 echo Pinned tags: "${pinned_tags[*]/#/#} "
@@ -689,7 +697,7 @@ _check_protocol() {
689_tag_gist() { 697_tag_gist() {
690 # if user want to change tags of a gist 698 # if user want to change tags of a gist
691 if [[ -z $@ ]]; then 699 if [[ -z $@ ]]; then
692 tag=true _show_list 700 display=tag _show_list
693 elif _gist_id $1 &>/dev/null; then 701 elif _gist_id $1 &>/dev/null; then
694 _show_detail $1 | sed 3,6d && echo 702 _show_detail $1 | sed 3,6d && echo
695 local desc="$(_get_desc $1)" 703 local desc="$(_get_desc $1)"
@@ -701,7 +709,7 @@ _tag_gist() {
701 # if user want to filter gists with given tags 709 # if user want to filter gists with given tags
702 else 710 else
703 local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /[[:space:]]|/g' <<<"$@") )" 711 local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /[[:space:]]|/g' <<<"$@") )"
704 hint=false tag=true _show_list | grep --color=always -E "$pattern" 712 hint=false mark=${INPUT:+.} display=tag _show_list | grep --color=always -E "$pattern"
705 fi 713 fi
706} 714}
707 715
@@ -748,6 +756,12 @@ _pin_tags() {
748 fi 756 fi
749} 757}
750 758
759# show languages of files in gists
760_gists_with_languages() {
761 local pattern="($(sed -E 's/([^ ]+)/#\1/g; s/ /|/g' <<<"$@"))"
762 hint=false mark=${INPUT:+.} display=language _show_list | grep --color=always -Ei "$pattern"
763}
764
751_apply_config "$@" || exit 1 765_apply_config "$@" || exit 1
752getConfiguredClient || exit 1 766getConfiguredClient || exit 1
753if [[ $init ]]; then _fetch_gists; exit 0; fi 767if [[ $init ]]; then _fetch_gists; exit 0; fi
@@ -799,6 +813,9 @@ case "$1" in
799 pin | p) 813 pin | p)
800 shift 814 shift
801 _pin_tags "$@" ;; 815 _pin_tags "$@" ;;
816 lan | l)
817 shift
818 _gists_with_languages "$@" ;;
802 version) 819 version)
803 echo "Version $currentVersion" ;; 820 echo "Version $currentVersion" ;;
804 update) 821 update)