From 38af58dad1edd1d71716e5684354e567efaa2679 Mon Sep 17 00:00:00 2001 From: typebrook Date: Wed, 1 Apr 2020 10:45:42 +0800 Subject: Refactor code --- gist | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gist b/gist index d4071da..996ad07 100755 --- a/gist +++ b/gist @@ -713,7 +713,7 @@ _check_protocol() { _tag_gist() { # if no tag is given, show gist list with tags - if [[ -z $@ ]]; then + if [[ -z $* ]]; then display=tag mark=${INPUT:+.} _show_list # if user want to change tags of a gist elif _gist_id $1 &>/dev/null; then @@ -750,7 +750,7 @@ _show_tags() { if [[ ${#pinned_tags} == 0 ]]; then echo 'Run "gist pin ..." to pin tags' else - echo Pinned tags: ${pinned_tags[@]/#/#} + echo Pinned tags: "${pinned_tags[@]/#/#}" fi } @@ -761,7 +761,7 @@ _pin_tags() { hint=false _tag_gist $pin else local new_pinned=( $(echo $pin $* | tr ' ' '\n' | sort | uniq -u | xargs) ) - for tag in ${new_pinned[@]}; do + for tag in "${new_pinned[@]}"; do if [[ $tag =~ [p]*[0-9]+ ]]; then echo Invalid tag: $tag return 1 @@ -770,7 +770,7 @@ _pin_tags() { pin="${new_pinned[@]}" _show_tags - sed -i'' -e "/^pin=/ d" "$CONFIG" && echo pin=\'"${new_pinned[@]}"\' >> "$CONFIG" + sed -i'' -e "/^pin=/ d" "$CONFIG" && echo pin=\'"${new_pinned[*]}"\' >> "$CONFIG" fi } @@ -781,8 +781,8 @@ _gists_with_languages() { } _gists_with_range() { - [[ ! $@ =~ ^s*[0-9]*-s*[0-9]*$ ]] && echo 'Invalid range' && exit 1 - local mark='' && [[ $@ =~ s ]] && mark=s + [[ ! $* =~ ^s*[0-9]*-s*[0-9]*$ ]] && echo 'Invalid range' && exit 1 + local mark='' && [[ $* =~ s ]] && mark=s local range=$(sed -Ee "s/s//g; s/^-/1-/; s/-$/-$(wc -l <$INDEX)/; s/-/\n/" <<< "$*") INPUT=$(seq $range | sed -e "s/^/p*$mark/") -- cgit v1.2.3-70-g09d2