From 60088611f31c1786bf2c47ac071d0592f5dfc0ea Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 2 Jul 2020 10:11:57 +0800 Subject: Fix logic error in format of grep Originally, the second filename would not contains 4 spaces at the beginning of the line --- gist | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/gist b/gist index ee0d55f..a28ec6e 100755 --- a/gist +++ b/gist @@ -48,7 +48,6 @@ # Since now a gist is a local cloned repo # It is your business to do git commit and git push -# FIXME g g s | g l # TODO IF in pipe, do not apply configure # TODO change gist from public to private or reverse versa # TODO feature to exclude tag-value or grep-string @@ -356,15 +355,15 @@ _grep_content() { else local repo=${folder}/${gist_id} [[ -d $repo ]] && cd $repo || continue - # grep from filenames - local file=$(ls $repo | grep --color=always -Ei "$1") - # grep from content of files - # Abort error message to prevent weird file name, for example: https://gist.github.com/6057f4a3a533f7992c60 - local content=$(grep --color=always -EHi -m1 "$1" * 2>/dev/null | head -1) - - [[ -n $file && file="$file\n" || -n $content ]] \ - && hint=false mark="$index " _print_records \ - && echo -e " $file$content" + local result=$({ + # grep from filenames + ls $repo | grep --color=always -Ei "$1" + # grep from content of files + # Abort error message to prevent weird file name, for example: https://gist.github.com/6057f4a3a533f7992c60 + grep --color=always -EHi -m1 "$1" * 2>/dev/null | head -1 + }) + + [[ -n $result ]] && hint=false mark="$index " _print_records && sed -e 's/^/ /' <<<"$result" fi done } -- cgit v1.2.3-70-g09d2