diff options
| author | typebrook <typebrook@gmail.com> | 2020-03-15 11:02:55 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-03-16 11:57:17 +0800 |
| commit | cb464605afbbad00a8381cdfc6b0facea6424538 (patch) | |
| tree | 3710b40a056666a5be8daff91a562b23288173e8 | |
| parent | e3aeb454276c4be56709b1560081f20ee8939f7f (diff) | |
A better grep
| -rwxr-xr-x | gist | 15 |
1 files changed, 14 insertions, 1 deletions
| @@ -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 |