Skip to content

Commit 7015041

Browse files
committed
improve find-in-jars: color grep match pattern #63
1 parent de16ef9 commit 7015041

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

docs/java.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- [:beer: find-in-jars](#beer-find-in-jars)
2121
- [用法](#%E7%94%A8%E6%B3%95-2)
2222
- [示例](#%E7%A4%BA%E4%BE%8B-2)
23+
- [运行效果](#%E8%BF%90%E8%A1%8C%E6%95%88%E6%9E%9C)
2324
- [参考资料](#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99)
2425

2526
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -399,6 +400,12 @@ WEB-INF/lib/aspectjweaver-1.8.8.jar!org/aspectj/weaver/XlintDefault.properties
399400
......
400401
```
401402
403+
### 运行效果
404+
405+
支持彩色输出,文件名中的匹配部分以`grep`的高亮方式显示。
406+
407+
![](https://user-images.githubusercontent.com/1063891/33545067-9eb66072-d8a2-11e7-8a77-d815c0979e5e.gif)
408+
402409
### 参考资料
403410
404411
[在多个Jar(Zip)文件查找Log4J配置文件的Shell命令行](http://oldratlee.com/458/tech/shell/find-file-in-jar-zip-files.html)

find-in-jars

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,17 @@ readonly total_count="$(echo "$jar_files" | wc -l)"
185185
exit 1
186186
}
187187

188+
$is_console && readonly grep_color_option='--color=always'
189+
188190
counter=1
189191
while read jar_file; do
190192
printResponsiveMessage "finding in jar($((counter++))/$total_count): $jar_file"
191193

192-
$command_for_list_zip "${jar_file}" | grep $regex_mode $ignore_case_option "$pattern" | while read file; do
194+
$command_for_list_zip "${jar_file}" | grep $regex_mode $ignore_case_option $grep_color_option -- "$pattern" | while read file; do
193195
clearResponsiveMessage
194196

195197
$is_console &&
196-
echo "$ec[1;31m${jar_file}$eend"\!"$ec[1;32m${file}$eend" ||
198+
echo "$ec[1;31m${jar_file}$eend$ec[1;32m"\!"$eend${file}" ||
197199
echo "${jar_file}"\!"${file}"
198200
done
199201

0 commit comments

Comments
 (0)