Skip to content

Commit

Permalink
improve find-in-jars: color grep match pattern #63
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Dec 4, 2017
1 parent de16ef9 commit 864fb2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- [:beer: find-in-jars](#beer-find-in-jars)
- [用法](#%E7%94%A8%E6%B3%95-2)
- [示例](#%E7%A4%BA%E4%BE%8B-2)
- [运行效果](#%E8%BF%90%E8%A1%8C%E6%95%88%E6%9E%9C)
- [参考资料](#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down Expand Up @@ -399,6 +400,12 @@ WEB-INF/lib/aspectjweaver-1.8.8.jar!org/aspectj/weaver/XlintDefault.properties
......
```
### 运行效果
支持彩色输出,文件名中的匹配部分以`grep`的高亮方式显示。
![](https://user-images.githubusercontent.com/1063891/33537698-8869fb0a-d882-11e7-9568-92afca3e7a29.gif)
### 参考资料
[在多个Jar(Zip)文件查找Log4J配置文件的Shell命令行](http://oldratlee.com/458/tech/shell/find-file-in-jar-zip-files.html)
6 changes: 4 additions & 2 deletions find-in-jars
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,17 @@ readonly total_count="$(echo "$jar_files" | wc -l)"
exit 1
}

$is_console && readonly grep_color_option='--color=always'

counter=1
while read jar_file; do
printResponsiveMessage "finding in jar($((counter++))/$total_count): $jar_file"

$command_for_list_zip "${jar_file}" | grep $regex_mode $ignore_case_option "$pattern" | while read file; do
$command_for_list_zip "${jar_file}" | grep $regex_mode $ignore_case_option $grep_color_option -- "$pattern" | while read file; do
clearResponsiveMessage

$is_console &&
echo "$ec[1;31m${jar_file}$eend"\!"$ec[1;32m${file}$eend" ||
echo "$ec[1;31m${jar_file}$eend$ec[1;33m"\!"$eend${file}" ||
echo "${jar_file}"\!"${file}"
done

Expand Down

0 comments on commit 864fb2c

Please sign in to comment.