aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-03-15 11:02:55 +0800
committertypebrook <typebrook@gmail.com>2020-03-16 11:57:17 +0800
commitcb464605afbbad00a8381cdfc6b0facea6424538 (patch)
tree3710b40a056666a5be8daff91a562b23288173e8
parente3aeb454276c4be56709b1560081f20ee8939f7f (diff)
A better grep
-rwxr-xr-xgist15
1 files changed, 14 insertions, 1 deletions
diff --git a/gist b/gist
index a85e826..4ee4ecd 100755
--- a/gist
+++ b/gist
@@ -276,7 +276,20 @@ _show_list() {
276 276
277# TODO support filenames, file contents 277# TODO support filenames, file contents
278_grep_content() { 278_grep_content() {
279 hint=false mark=. _show_list | grep -Ei "^ *[^ ]+ [^ ]+ .*$1.*" 279 while read -r index url _ _ _ _ _ _ description; do
280 if grep --color=always -iq "$1" <<<"$description"; then
281 hint=false mark="$index " _show_list | grep --color=always -Ei "$1"
282 else
283 repo=$folder/$(echo $url | sed -E -e 's#.*/##')
284 [[ -d $repo ]] && cd $repo || continue
285 file=$(ls $repo | grep --color=always -Ei "$1")
286 content=$(grep --color=always -EHi "$1" * | head -1)
287
288 [[ -n $file && file="$file\n" || -n $content ]] \
289 && hint=false mark="$index " _show_list \
290 && echo -e "$file$content\n" | sed -e 's/^/ /'
291 fi
292 done < $INDEX
280} 293}
281 294
282# Open Github repository import page 295# Open Github repository import page