diff options
author | typebrook <typebrook@gmail.com> | 2020-04-12 23:25:39 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-04-13 17:23:14 +0800 |
commit | 5014a06a40087ceb80abe4127d37979c18f97345 (patch) | |
tree | fee9a4f99e8de636382a51cebe44a43839c977fb | |
parent | 0938ab431a001fced7b6a6ecace89a08ae0e3398 (diff) |
Process more after 'gist fetch'
-rwxr-xr-x | gist | 64 |
1 files changed, 34 insertions, 30 deletions
@@ -61,7 +61,7 @@ configuredClient="" | |||
61 | GITHUB_API=https://api.github.com | 61 | GITHUB_API=https://api.github.com |
62 | CONFIG=~/.config/gist.conf; mkdir -p ~/.config | 62 | CONFIG=~/.config/gist.conf; mkdir -p ~/.config |
63 | 63 | ||
64 | INDEX_FORMAT=('index' 'url' 'blob_code' 'file_array' 'file_num' 'comment_num' 'author' 'created_at' 'updated_at' 'description') | 64 | INDEX_FORMAT=('index' 'url' 'tags_string' 'blob_code' 'file_array' 'file_num' 'comment_num' 'author' 'created_at' 'updated_at' 'description') |
65 | TAG_CHAR='-_[:alnum:]' | 65 | TAG_CHAR='-_[:alnum:]' |
66 | [[ ! -t 0 ]] && INPUT=$(cat) | 66 | [[ ! -t 0 ]] && INPUT=$(cat) |
67 | [[ ! -t 1 && -z $hint ]] && hint=false | 67 | [[ ! -t 1 && -z $hint ]] && hint=false |
@@ -303,21 +303,21 @@ _show_list() { | |||
303 | 303 | ||
304 | sed -Ee "/^${mark:-[^s]}/ !d; /^$(_index_pattern) / !d" $INDEX \ | 304 | sed -Ee "/^${mark:-[^s]}/ !d; /^$(_index_pattern) / !d" $INDEX \ |
305 | | while read -r "${INDEX_FORMAT[@]}"; do | 305 | | while read -r "${INDEX_FORMAT[@]}"; do |
306 | local extra=$(_check_repo_status "$folder/${url##*/}" "$blob_code") | ||
307 | [[ -z $extra ]] && extra="$(printf "%-4s" "$file_num $comment_num")" | ||
308 | local hashtags=$(_hashtags "$description") | ||
309 | [[ $index =~ ^s ]] && description="$(printf "%-12s" [${author}]) ${description}" | ||
310 | description=$(sed -E -e 's/^\[(.+)\]/\\e[33m[\1]\\e[0m/' <<<"$description" | sed "s/ $hashtags$//") | ||
311 | |||
312 | local message=$url | 306 | local message=$url |
313 | if [[ $display == 'tag' ]]; then | 307 | if [[ $display == 'tag' ]]; then |
314 | [[ $show_untagged == 'false' && -z $hashtags ]] && continue | 308 | local tags=( ${tags_string//,/ } ); message="${tags[@]}" |
315 | message="$hashtags"; local width=45; local align=' '; extra=''; | 309 | [[ $show_untagged == 'false' && ${#tags[@]} == '0' ]] && continue |
310 | local width=45; local align=' '; extra=''; | ||
316 | elif [[ $display == 'language' ]]; then | 311 | elif [[ $display == 'language' ]]; then |
317 | message="$(tr ',' '\n' <<< $file_array | sed -Ee 's/.+@/#/' | uniq | xargs)" | 312 | message="$(tr ',' '\n' <<< $file_array | sed -Ee 's/.+@/#/' | uniq | xargs)" |
318 | local width=45; local align=' '; extra=''; | 313 | local width=45; local align=' '; extra=''; |
319 | fi | 314 | fi |
320 | 315 | ||
316 | local extra=$(_check_repo_status "$folder/${url##*/}" "$blob_code") | ||
317 | [[ -z $extra ]] && extra="$(printf "%-4s" "$file_num $comment_num")" | ||
318 | |||
319 | [[ $index =~ ^s ]] && description="$(printf "%-12s" [${author}]) ${description}" | ||
320 | |||
321 | raw_output="$(printf "%-3s" "$index") $(printf "%${align:--}${width:-56}s" "$message") $extra $description" | 321 | raw_output="$(printf "%-3s" "$index") $(printf "%${align:--}${width:-56}s" "$message") $extra $description" |
322 | [[ -n $pin ]] && raw_output="$(_color_pinned_tags "$raw_output")" | 322 | [[ -n $pin ]] && raw_output="$(_color_pinned_tags "$raw_output")" |
323 | decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 )) | 323 | decorator=$(( $(grep -o '\\e\[0m' <<<"$raw_output" | wc -l) *9 )) |
@@ -344,8 +344,7 @@ _grep_content() { | |||
344 | sed -Ee "/^$(_index_pattern) / !d" $INDEX \ | 344 | sed -Ee "/^$(_index_pattern) / !d" $INDEX \ |
345 | | while read -r "${INDEX_FORMAT[@]}"; do | 345 | | while read -r "${INDEX_FORMAT[@]}"; do |
346 | # grep from description | 346 | # grep from description |
347 | local hashtags="$(_hashtags "$description")" | 347 | if grep --color=always -iq "$1" <<<"$description"; then |
348 | if grep --color=always -iq "$1" <<<"${description%% $hashtags}"; then | ||
349 | hint=false mark="$index " _show_list | 348 | hint=false mark="$index " _show_list |
350 | else | 349 | else |
351 | local repo=$folder/${url##*/} | 350 | local repo=$folder/${url##*/} |
@@ -384,11 +383,17 @@ for gist in raw: | |||
384 | _parse_response() { | 383 | _parse_response() { |
385 | _parse_gists \ | 384 | _parse_gists \ |
386 | | tac | nl -s' ' \ | 385 | | tac | nl -s' ' \ |
387 | | while read -r "${INDEX_FORMAT[@]:0:2}" public file_url_array "${INDEX_FORMAT[@]:3:7}"; do | 386 | | while read -r "${INDEX_FORMAT[@]:0:2}" public file_url_array "${INDEX_FORMAT[@]:4:7}"; do |
388 | local blob_code; blob_code=$(echo "$file_url_array" | tr ',' '\n' | sed -E -e 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -s -d '-' -) | ||
389 | local prefix=$mark; [[ $public == 'False' ]] && prefix=p | 387 | local prefix=$mark; [[ $public == 'False' ]] && prefix=p |
390 | [[ -n $1 ]] && local index=${1}; index=${prefix}${index} | 388 | [[ -n $1 ]] && local index=${1}; index=${prefix}${index} |
389 | |||
390 | local blob_code=$(echo "$file_url_array" | tr ',' '\n' | sed -E -e 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -s -d '-' -) | ||
391 | file_array=${file_array//@None/@Text} | 391 | file_array=${file_array//@None/@Text} |
392 | |||
393 | local hashtags="$(_hashtags "$description")" | ||
394 | local tags_string=${hashtags// /,}; [[ -z $tags_string ]] && tags_string=',' | ||
395 | description="$(sed -E -e 's/^\[(.+)\]/\\e[33m[\1]\\e[0m/' <<<"${description%$hashtags}")" | ||
396 | |||
392 | eval echo "${INDEX_FORMAT[@]/#/$}" | 397 | eval echo "${INDEX_FORMAT[@]/#/$}" |
393 | done | 398 | done |
394 | } | 399 | } |
@@ -564,15 +569,14 @@ _show_detail() { | |||
564 | 569 | ||
565 | sed -En -e "/[^ ]+ [^ ]+$GIST_ID / p" $INDEX \ | 570 | sed -En -e "/[^ ]+ [^ ]+$GIST_ID / p" $INDEX \ |
566 | | while read -r "${INDEX_FORMAT[@]}"; do | 571 | | while read -r "${INDEX_FORMAT[@]}"; do |
567 | local hashtags=$(_hashtags "$description") | 572 | echo -e desc: $description |
568 | echo desc: ${description%% $hashtags} | 573 | echo -e tags: ${tags_string//,/ } |
569 | echo tags: $hashtags | 574 | echo -e site: https://gist.github.com/$GIST_ID |
570 | echo site: https://gist.github.com/$GIST_ID | 575 | echo -e API : https://api.github.com/gists/$GIST_ID |
571 | echo API : https://api.github.com/gists/$GIST_ID | 576 | echo -e created_at: $created_at |
572 | echo created_at: $created_at | 577 | echo -e updated_at: $updated_at |
573 | echo updated_at: $updated_at | 578 | echo -e files: |
574 | echo files: | 579 | echo -e $file_array | tr ',' '\n' | tr '@' ' ' \ |
575 | echo $file_array | tr ',' '\n' | tr '@' ' ' \ | ||
576 | | column -t | sed -e 's/^/ /' | 580 | | column -t | sed -e 's/^/ /' |
577 | done | 581 | done |
578 | } | 582 | } |
@@ -678,9 +682,9 @@ _create_gist() { | |||
678 | fi | 682 | fi |
679 | } | 683 | } |
680 | 684 | ||
681 | # get the gist description with a given index | 685 | # get the gist description with a given index (color is removed) |
682 | _get_desc() { | 686 | _get_desc() { |
683 | sed -ne "/^$1 / p" $INDEX | cut -d' ' -f${#INDEX_FORMAT[@]}- | 687 | sed -ne "/^$1 / p" $INDEX | cut -d' ' -f${#INDEX_FORMAT[@]}- | sed 's/\\e\[[0-9;]\+[A-Za-z]//g' |
684 | } | 688 | } |
685 | 689 | ||
686 | # Update description of a gist | 690 | # Update description of a gist |
@@ -731,10 +735,10 @@ _tag_gist() { | |||
731 | display=tag mark=${INPUT:+.} _show_list | 735 | display=tag mark=${INPUT:+.} _show_list |
732 | # if user want to change tags of a gist | 736 | # if user want to change tags of a gist |
733 | elif _gist_id $1 &>/dev/null; then | 737 | elif _gist_id $1 &>/dev/null; then |
734 | _show_detail $1 | sed 3,6d && echo | 738 | detail="$(_show_detail $1 | sed 3,6d | tee /dev/tty)"; echo |
735 | local desc="$(_get_desc $1)" | 739 | local desc="$(echo "$detail" | sed -ne 1p | cut -d' ' -f2-)" |
736 | local hashtags=$(_hashtags "$desc") | 740 | local tags="$(echo "$detail" | sed -ne '2 s/#//gp' | cut -d' ' -f2-)" |
737 | read -e -p 'Edit tags: ' -i "${hashtags//'#'/}" -r -a new_tags < /dev/tty | 741 | read -e -p 'Edit tags: ' -i "$tags" -r -a new_tags < /dev/tty |
738 | local new_hashtags="${new_tags[@]/#/#}" | 742 | local new_hashtags="${new_tags[@]/#/#}" |
739 | local new_desc=$(sed "s/$hashtags$//; s/ *$/ /" <<<"$desc")${new_hashtags} | 743 | local new_desc=$(sed "s/$hashtags$//; s/ *$/ /" <<<"$desc")${new_hashtags} |
740 | (_edit_gist $1 "$new_desc" &>/dev/null &) | 744 | (_edit_gist $1 "$new_desc" &>/dev/null &) |
@@ -749,8 +753,8 @@ _tag_gist() { | |||
749 | _show_tags() { | 753 | _show_tags() { |
750 | local pinned_tags=( $pin ) | 754 | local pinned_tags=( $pin ) |
751 | local tags=$(while read -r "${INDEX_FORMAT[@]}"; do | 755 | local tags=$(while read -r "${INDEX_FORMAT[@]}"; do |
752 | _hashtags "$description" | tr ' ' '\n' | sed -e '/^$/d' | 756 | echo ${tags_string//,/ } |
753 | done < $INDEX | sort -u) | 757 | done < $INDEX | tr ' ' '\n' | sed -e '/^$/d' | sort -u) |
754 | 758 | ||
755 | for prefix in {0..9} {a..z} {A-Z} [^0-9a-zA-Z]; do | 759 | for prefix in {0..9} {a..z} {A-Z} [^0-9a-zA-Z]; do |
756 | local line=$(echo $tags | grep -Eo "#$prefix[^ ]+" | tr '\n' ' ') | 760 | local line=$(echo $tags | grep -Eo "#$prefix[^ ]+" | tr '\n' ' ') |