diff options
| author | typebrook <typebrook@gmail.com> | 2020-04-01 10:45:42 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-04-07 00:04:44 +0800 |
| commit | 38af58dad1edd1d71716e5684354e567efaa2679 (patch) | |
| tree | ffa544d5cc4dc53b53072f89339d721fcd92b3b4 | |
| parent | 1c7b1a1b47dd04d97dc4fad87c4866a0ba2e99aa (diff) | |
Refactor code
| -rwxr-xr-x | gist | 12 |
1 files changed, 6 insertions, 6 deletions
| @@ -713,7 +713,7 @@ _check_protocol() { | |||
| 713 | 713 | ||
| 714 | _tag_gist() { | 714 | _tag_gist() { |
| 715 | # if no tag is given, show gist list with tags | 715 | # if no tag is given, show gist list with tags |
| 716 | if [[ -z $@ ]]; then | 716 | if [[ -z $* ]]; then |
| 717 | display=tag mark=${INPUT:+.} _show_list | 717 | display=tag mark=${INPUT:+.} _show_list |
| 718 | # if user want to change tags of a gist | 718 | # if user want to change tags of a gist |
| 719 | elif _gist_id $1 &>/dev/null; then | 719 | elif _gist_id $1 &>/dev/null; then |
| @@ -750,7 +750,7 @@ _show_tags() { | |||
| 750 | if [[ ${#pinned_tags} == 0 ]]; then | 750 | if [[ ${#pinned_tags} == 0 ]]; then |
| 751 | echo 'Run "gist pin <tag1> <tag2>..." to pin tags' | 751 | echo 'Run "gist pin <tag1> <tag2>..." to pin tags' |
| 752 | else | 752 | else |
| 753 | echo Pinned tags: ${pinned_tags[@]/#/#} | 753 | echo Pinned tags: "${pinned_tags[@]/#/#}" |
| 754 | fi | 754 | fi |
| 755 | } | 755 | } |
| 756 | 756 | ||
| @@ -761,7 +761,7 @@ _pin_tags() { | |||
| 761 | hint=false _tag_gist $pin | 761 | hint=false _tag_gist $pin |
| 762 | else | 762 | else |
| 763 | local new_pinned=( $(echo $pin $* | tr ' ' '\n' | sort | uniq -u | xargs) ) | 763 | local new_pinned=( $(echo $pin $* | tr ' ' '\n' | sort | uniq -u | xargs) ) |
| 764 | for tag in ${new_pinned[@]}; do | 764 | for tag in "${new_pinned[@]}"; do |
| 765 | if [[ $tag =~ [p]*[0-9]+ ]]; then | 765 | if [[ $tag =~ [p]*[0-9]+ ]]; then |
| 766 | echo Invalid tag: $tag | 766 | echo Invalid tag: $tag |
| 767 | return 1 | 767 | return 1 |
| @@ -770,7 +770,7 @@ _pin_tags() { | |||
| 770 | 770 | ||
| 771 | pin="${new_pinned[@]}" | 771 | pin="${new_pinned[@]}" |
| 772 | _show_tags | 772 | _show_tags |
| 773 | sed -i'' -e "/^pin=/ d" "$CONFIG" && echo pin=\'"${new_pinned[@]}"\' >> "$CONFIG" | 773 | sed -i'' -e "/^pin=/ d" "$CONFIG" && echo pin=\'"${new_pinned[*]}"\' >> "$CONFIG" |
| 774 | fi | 774 | fi |
| 775 | } | 775 | } |
| 776 | 776 | ||
| @@ -781,8 +781,8 @@ _gists_with_languages() { | |||
| 781 | } | 781 | } |
| 782 | 782 | ||
| 783 | _gists_with_range() { | 783 | _gists_with_range() { |
| 784 | [[ ! $@ =~ ^s*[0-9]*-s*[0-9]*$ ]] && echo 'Invalid range' && exit 1 | 784 | [[ ! $* =~ ^s*[0-9]*-s*[0-9]*$ ]] && echo 'Invalid range' && exit 1 |
| 785 | local mark='' && [[ $@ =~ s ]] && mark=s | 785 | local mark='' && [[ $* =~ s ]] && mark=s |
| 786 | 786 | ||
| 787 | local range=$(sed -Ee "s/s//g; s/^-/1-/; s/-$/-$(wc -l <$INDEX)/; s/-/\n/" <<< "$*") | 787 | local range=$(sed -Ee "s/s//g; s/^-/1-/; s/-$/-$(wc -l <$INDEX)/; s/-/\n/" <<< "$*") |
| 788 | INPUT=$(seq $range | sed -e "s/^/p*$mark/") | 788 | INPUT=$(seq $range | sed -e "s/^/p*$mark/") |