diff options
| author | typebrook <typebrook@gmail.com> | 2020-03-16 13:54:55 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-03-16 13:56:03 +0800 |
| commit | 08975f394c6357d28cad479efa7a95872190ca8a (patch) | |
| tree | ea48edc3a434b3fd3286d913b17cde25d3b48ca3 | |
| parent | 837657f5ee10dfd7c78b53f2548b5e83d93714d3 (diff) | |
| parent | 159dae1e649665701a4777cbff59e9bc6ccfc44b (diff) | |
Merge branch 'grep' into master
| -rwxr-xr-x | gist | 16 |
1 files changed, 15 insertions, 1 deletions
| @@ -276,7 +276,21 @@ _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 | if [[ -z $1 ]]; then echo 'Please give a pattern' && return 1; fi |
| 280 | while read -r index url _ _ _ _ _ _ description; do | ||
| 281 | if grep --color=always -iq "$1" <<<"$description"; then | ||
| 282 | hint=false mark="$index " _show_list | grep --color=always -Ei "$1" | ||
| 283 | else | ||
| 284 | repo=$folder/$(echo $url | sed -E -e 's#.*/##') | ||
| 285 | [[ -d $repo ]] && cd $repo || continue | ||
| 286 | file=$(ls $repo | grep --color=always -Ei "$1") | ||
| 287 | content=$(grep --color=always -EHi "$1" * | head -1) | ||
| 288 | |||
| 289 | [[ -n $file && file="$file\n" || -n $content ]] \ | ||
| 290 | && hint=false mark="$index " _show_list \ | ||
| 291 | && echo -e "$file$content\n" | sed -e 's/^/ /' | ||
| 292 | fi | ||
| 293 | done < $INDEX | ||
| 280 | } | 294 | } |
| 281 | 295 | ||
| 282 | # Open Github repository import page | 296 | # Open Github repository import page |