diff options
author | typebrook <typebrook@gmail.com> | 2020-03-17 13:43:26 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-03-17 17:56:13 +0800 |
commit | 6018e546ab3d283a71d21479f2e73cfd334bd158 (patch) | |
tree | 4adb4c40b7a50ca1699acd4bfed3e6b7d0f9770e | |
parent | 1ce51de24d2ddee6e8868100c960e0bc2f85a798 (diff) |
Refactor code
-rwxr-xr-x | gist | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -287,14 +287,14 @@ _show_list() { | |||
287 | # TODO add option to configure case-sensitive | 287 | # TODO add option to configure case-sensitive |
288 | _grep_content() { | 288 | _grep_content() { |
289 | if [[ -z $1 ]]; then echo 'Please give a pattern' && return 1; fi | 289 | if [[ -z $1 ]]; then echo 'Please give a pattern' && return 1; fi |
290 | while read -r index url _ _ _ _ _ _ description; do | 290 | while read -r "${INDEX_FORMAT[@]}"; do |
291 | if grep --color=always -iq "$1" <<<"$description"; then | 291 | if grep --color=always -iq "$1" <<<"$description"; then |
292 | hint=false mark="$index " _show_list | grep --color=always -Ei "$1" | 292 | hint=false mark="$index " _show_list | grep --color=always -Ei "$1" |
293 | else | 293 | else |
294 | repo=$folder/$(echo $url | sed -E -e 's#.*/##') | 294 | local repo=$folder/$(echo $url | sed -E -e 's#.*/##') |
295 | [[ -d $repo ]] && cd $repo || continue | 295 | [[ -d $repo ]] && cd $repo || continue |
296 | file=$(ls $repo | grep --color=always -Ei "$1") | 296 | local file=$(ls $repo | grep --color=always -Ei "$1") |
297 | content=$(grep --color=always -EHi "$1" * | head -1) | 297 | local content=$(grep --color=always -EHi "$1" * | head -1) |
298 | 298 | ||
299 | [[ -n $file && file="$file\n" || -n $content ]] \ | 299 | [[ -n $file && file="$file\n" || -n $content ]] \ |
300 | && hint=false mark="$index " _show_list \ | 300 | && hint=false mark="$index " _show_list \ |
@@ -509,7 +509,7 @@ _import_to_github() { | |||
509 | 509 | ||
510 | # Simply commit current changes and push to remote | 510 | # Simply commit current changes and push to remote |
511 | _push_to_remote() { | 511 | _push_to_remote() { |
512 | if [[ ! `pwd` =~ ^$folder/[0-9a-z]+$ ]]; then | 512 | if [[ ! $(pwd) =~ ^$folder/[0-9a-z]+$ ]]; then |
513 | _gist_id "$1" | 513 | _gist_id "$1" |
514 | cd "$folder/$GIST_ID" || return 1 | 514 | cd "$folder/$GIST_ID" || return 1 |
515 | fi | 515 | fi |
@@ -623,9 +623,9 @@ _check_protocol() { | |||
623 | cd "$repo" || exit 1 | 623 | cd "$repo" || exit 1 |
624 | url=$(git remote get-url origin) | 624 | url=$(git remote get-url origin) |
625 | if [[ $protocol == 'ssh' && $url =~ ^https ]]; then | 625 | if [[ $protocol == 'ssh' && $url =~ ^https ]]; then |
626 | git remote set-url origin "git@gist.github.com:$(basename `pwd`).git" | 626 | git remote set-url origin "git@gist.github.com:$(basename $(pwd)).git" |
627 | elif [[ $protocol == 'https' && $url =~ ^git ]]; then | 627 | elif [[ $protocol == 'https' && $url =~ ^git ]]; then |
628 | git remote set-url origin "https://gist.github.com/$(basename `pwd`).git" | 628 | git remote set-url origin "https://gist.github.com/$(basename $(pwd)).git" |
629 | fi | 629 | fi |
630 | done | 630 | done |
631 | } | 631 | } |