From cb464605afbbad00a8381cdfc6b0facea6424538 Mon Sep 17 00:00:00 2001 From: typebrook Date: Sun, 15 Mar 2020 11:02:55 +0800 Subject: A better grep --- gist | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gist b/gist index a85e826..4ee4ecd 100755 --- a/gist +++ b/gist @@ -276,7 +276,20 @@ _show_list() { # TODO support filenames, file contents _grep_content() { - hint=false mark=. _show_list | grep -Ei "^ *[^ ]+ [^ ]+ .*$1.*" + while read -r index url _ _ _ _ _ _ description; do + if grep --color=always -iq "$1" <<<"$description"; then + hint=false mark="$index " _show_list | grep --color=always -Ei "$1" + else + repo=$folder/$(echo $url | sed -E -e 's#.*/##') + [[ -d $repo ]] && cd $repo || continue + file=$(ls $repo | grep --color=always -Ei "$1") + content=$(grep --color=always -EHi "$1" * | head -1) + + [[ -n $file && file="$file\n" || -n $content ]] \ + && hint=false mark="$index " _show_list \ + && echo -e "$file$content\n" | sed -e 's/^/ /' + fi + done < $INDEX } # Open Github repository import page -- cgit v1.2.3-70-g09d2