diff options
author | typebrook <typebrook@gmail.com> | 2020-03-18 10:45:29 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-03-18 11:54:18 +0800 |
commit | 1c4ff2d1688bd39742bf7565c45239aaf7e134e7 (patch) | |
tree | 042b5aad0d4f60c04e18d25ca6b3a54b95fb7632 | |
parent | 1c17a1f5eb9ee36524b23b1760f3b18770d3224f (diff) |
Apply hashtags to 'gist detail'
- a standalone function to extract hashtags from description
- in 'gist detail', split puse description and trailing tags into 2
lines for a clear format
-rwxr-xr-x | gist | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -236,6 +236,11 @@ _apply_config() { | |||
236 | INDEX=$folder/index; [[ -e $INDEX ]] || touch $INDEX | 236 | INDEX=$folder/index; [[ -e $INDEX ]] || touch $INDEX |
237 | } | 237 | } |
238 | 238 | ||
239 | # extract trailing hashtags from description | ||
240 | _hashtags() { | ||
241 | grep -Eo ' #[[:alnum:]\-\_ #]+$' <<<"$1" | sed -Ee 's/.* [[:alnum:]\-\_]+//g' | xargs | ||
242 | } | ||
243 | |||
239 | # Return git status of a given repo | 244 | # Return git status of a given repo |
240 | _check_repo_status() { | 245 | _check_repo_status() { |
241 | if [[ ! -d $1 ]]; then | 246 | if [[ ! -d $1 ]]; then |
@@ -491,8 +496,10 @@ for comment in raw: | |||
491 | _show_detail() { | 496 | _show_detail() { |
492 | _gist_id "$1" || return 1 | 497 | _gist_id "$1" || return 1 |
493 | sed -n "/^$1 / p" $INDEX \ | 498 | sed -n "/^$1 / p" $INDEX \ |
494 | | while read -r ${INDEX_FORMAT[@]}; do | 499 | | while read -r "${INDEX_FORMAT[@]}"; do |
495 | echo description: $description | 500 | local hashtags=$(_hashtags "$description") |
501 | echo description: ${description%% $hashtags} | ||
502 | echo tags: $hashtags | ||
496 | echo site: https://gist.github.com/$GIST_ID | 503 | echo site: https://gist.github.com/$GIST_ID |
497 | echo API: https://api.github.com/gists/$GIST_ID | 504 | echo API: https://api.github.com/gists/$GIST_ID |
498 | echo created_at: $created_at | 505 | echo created_at: $created_at |
@@ -648,9 +655,9 @@ _check_protocol() { | |||
648 | _tag_gist() { | 655 | _tag_gist() { |
649 | # if user want to change tags of a gist | 656 | # if user want to change tags of a gist |
650 | if _gist_id $1 &>/dev/null; then | 657 | if _gist_id $1 &>/dev/null; then |
651 | _show_detail $1 | sed 2,5d && echo | 658 | _show_detail $1 | sed 3,6d && echo |
652 | local desc="$(_get_desc $1)" | 659 | local desc="$(_get_desc $1)" |
653 | local hashtags=$(grep -Eo ' #[[:alnum:]\-\_ #]+$' <<<"$desc" | sed -Ee 's/.* [[:alnum:]\-\_]+//g' | xargs) | 660 | local hashtags=$(_hashtags "$desc") |
654 | read -e -p 'Edit tags: ' -i "$(tr -d '#' <<<"$hashtags")" -r new_tags < /dev/tty | 661 | read -e -p 'Edit tags: ' -i "$(tr -d '#' <<<"$hashtags")" -r new_tags < /dev/tty |
655 | local new_hashtags=$(sed -Ee 's/^/#/; s/ / #/g' <<<"$new_tags") | 662 | local new_hashtags=$(sed -Ee 's/^/#/; s/ / #/g' <<<"$new_tags") |
656 | local new_desc=$(sed "s/$hashtags$//; s/ *$/ /" <<<"$desc")${new_hashtags} | 663 | local new_desc=$(sed "s/$hashtags$//; s/ *$/ /" <<<"$desc")${new_hashtags} |