From 77a38c07d336cc9087e404a550f19b898d1e8b52 Mon Sep 17 00:00:00 2001 From: typebrook Date: Fri, 27 Mar 2020 22:07:33 +0800 Subject: Refator grep in 'gist grep' to speed up --- gist | 6 +++--- 1 file 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() { # grep from description local hashtags="$(_hashtags "$description")" if grep --color=always -iq "$1" <<<"${description%% $hashtags}"; then - hint=false mark="$index " _show_list | grep --color=always -Ei "$1" + hint=false mark="$index " _show_list else local repo=$folder/${url##*/} [[ -d $repo ]] && cd $repo || continue # grep from filenames local file=$(ls $repo | grep --color=always -Ei "$1") # grep from content of files - local content=$(grep --color=always -EHi "$1" * | head -1) + local content=$(grep --color=always -EHi -m1 "$1" *) [[ -n $file && file="$file\n" || -n $content ]] \ && hint=false mark="$index " _show_list \ && echo -e " $file$content" fi - done + done | grep --color=always -Ei -C1 "$1" } # Parse JSON object of the result of gist fetch -- cgit v1.2.3-70-g09d2