aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-03-18 10:45:29 +0800
committertypebrook <typebrook@gmail.com>2020-03-18 11:54:18 +0800
commit1c4ff2d1688bd39742bf7565c45239aaf7e134e7 (patch)
tree042b5aad0d4f60c04e18d25ca6b3a54b95fb7632
parent1c17a1f5eb9ee36524b23b1760f3b18770d3224f (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-xgist15
1 files changed, 11 insertions, 4 deletions
diff --git a/gist b/gist
index 8017445..c624def 100755
--- a/gist
+++ b/gist
@@ -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}