aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-03-27 22:07:33 +0800
committertypebrook <typebrook@gmail.com>2020-03-27 23:35:33 +0800
commit77a38c07d336cc9087e404a550f19b898d1e8b52 (patch)
treefd3300e0bf73521976bec93ee298795d733f9a79
parent1925a8e126a054b5021425122b45739a99053b44 (diff)
Refator grep in 'gist grep' to speed up
-rwxr-xr-xgist6
1 files changed, 3 insertions, 3 deletions
diff --git a/gist b/gist
index daf57ad..789ef85 100755
--- a/gist
+++ b/gist
@@ -327,20 +327,20 @@ _grep_content() {
327 # grep from description 327 # grep from description
328 local hashtags="$(_hashtags "$description")" 328 local hashtags="$(_hashtags "$description")"
329 if grep --color=always -iq "$1" <<<"${description%% $hashtags}"; then 329 if grep --color=always -iq "$1" <<<"${description%% $hashtags}"; then
330 hint=false mark="$index " _show_list | grep --color=always -Ei "$1" 330 hint=false mark="$index " _show_list
331 else 331 else
332 local repo=$folder/${url##*/} 332 local repo=$folder/${url##*/}
333 [[ -d $repo ]] && cd $repo || continue 333 [[ -d $repo ]] && cd $repo || continue
334 # grep from filenames 334 # grep from filenames
335 local file=$(ls $repo | grep --color=always -Ei "$1") 335 local file=$(ls $repo | grep --color=always -Ei "$1")
336 # grep from content of files 336 # grep from content of files
337 local content=$(grep --color=always -EHi "$1" * | head -1) 337 local content=$(grep --color=always -EHi -m1 "$1" *)
338 338
339 [[ -n $file && file="$file\n" || -n $content ]] \ 339 [[ -n $file && file="$file\n" || -n $content ]] \
340 && hint=false mark="$index " _show_list \ 340 && hint=false mark="$index " _show_list \
341 && echo -e " $file$content" 341 && echo -e " $file$content"
342 fi 342 fi
343 done 343 done | grep --color=always -Ei -C1 "$1"
344} 344}
345 345
346# Parse JSON object of the result of gist fetch 346# Parse JSON object of the result of gist fetch