1 |
commit: 92192efb2f621ad13a412d659bb682989a301acc |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Apr 28 08:50:43 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Apr 28 08:50:43 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=92192efb |
7 |
|
8 |
qgrep: use colours for atom printing, and support -R/--repo |
9 |
|
10 |
use same colour scheme as with qlist, qdepends, etc. |
11 |
support printing repo for ebuilds mode |
12 |
|
13 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
14 |
|
15 |
man/qgrep.1 | 3 +++ |
16 |
qgrep.c | 43 ++++++++++++++++++++++++++----------------- |
17 |
2 files changed, 29 insertions(+), 17 deletions(-) |
18 |
|
19 |
diff --git a/man/qgrep.1 b/man/qgrep.1 |
20 |
index 347c88c..34fe54d 100644 |
21 |
--- a/man/qgrep.1 |
22 |
+++ b/man/qgrep.1 |
23 |
@@ -50,6 +50,9 @@ Search in eclasses instead of ebuilds. |
24 |
\fB\-s\fR, \fB\-\-skip\-comments\fR |
25 |
Skip comments lines. |
26 |
.TP |
27 |
+\fB\-R\fR, \fB\-\-repo\fR |
28 |
+Print source repository name for each match (implies -N). |
29 |
+.TP |
30 |
\fB\-S\fR \fI<arg>\fR, \fB\-\-skip\fR \fI<arg>\fR |
31 |
Skip lines matching <arg>. |
32 |
.TP |
33 |
|
34 |
diff --git a/qgrep.c b/qgrep.c |
35 |
index 3950c22..9d78c18 100644 |
36 |
--- a/qgrep.c |
37 |
+++ b/qgrep.c |
38 |
@@ -25,7 +25,7 @@ |
39 |
#include "xchdir.h" |
40 |
#include "xregex.h" |
41 |
|
42 |
-#define QGREP_FLAGS "IiHNclLexJEsS:B:A:" COMMON_FLAGS |
43 |
+#define QGREP_FLAGS "IiHNclLexJEsRS:B:A:" COMMON_FLAGS |
44 |
static struct option const qgrep_long_opts[] = { |
45 |
{"invert-match", no_argument, NULL, 'I'}, |
46 |
{"ignore-case", no_argument, NULL, 'i'}, |
47 |
@@ -39,6 +39,7 @@ static struct option const qgrep_long_opts[] = { |
48 |
{"installed", no_argument, NULL, 'J'}, |
49 |
{"eclass", no_argument, NULL, 'E'}, |
50 |
{"skip-comments", no_argument, NULL, 's'}, |
51 |
+ {"repo", no_argument, NULL, 'R'}, |
52 |
{"skip", a_argument, NULL, 'S'}, |
53 |
{"before", a_argument, NULL, 'B'}, |
54 |
{"after", a_argument, NULL, 'A'}, |
55 |
@@ -57,6 +58,7 @@ static const char * const qgrep_opts_help[] = { |
56 |
"Search in installed ebuilds instead of the tree", |
57 |
"Search in eclasses instead of ebuilds", |
58 |
"Skip comments lines", |
59 |
+ "Print source repository name for each match (implies -N)", |
60 |
"Skip lines matching <arg>", |
61 |
"Print <arg> lines of leading context", |
62 |
"Print <arg> lines of trailing context", |
63 |
@@ -198,6 +200,7 @@ struct qgrep_grepargs { |
64 |
bool do_list:1; |
65 |
bool show_filename:1; |
66 |
bool show_name:1; |
67 |
+ bool show_repo:1; |
68 |
bool skip_comments:1; |
69 |
bool invert_list:1; |
70 |
bool invert_match:1; |
71 |
@@ -421,7 +424,10 @@ qgrep_cache_cb(cache_pkg_ctx *pkg_ctx, void *priv) |
72 |
|
73 |
label = NULL; |
74 |
if (data->show_name) { |
75 |
- snprintf(name, sizeof(name), "%s/%s", patom->CATEGORY, patom->P); |
76 |
+ char *repo = data->show_repo ? cctx->repo : NULL; |
77 |
+ snprintf(name, sizeof(name), "%s%s/%s%s%s%s%s%s", |
78 |
+ BOLD, patom->CATEGORY, BLUE, patom->P, GREEN, |
79 |
+ repo ? "::" : "", repo ? repo : "", NORM); |
80 |
label = name; |
81 |
} else if (data->show_filename) { |
82 |
label = buf; |
83 |
@@ -473,7 +479,8 @@ qgrep_vdb_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) |
84 |
|
85 |
label = NULL; |
86 |
if (data->show_name) { |
87 |
- snprintf(name, sizeof(name), "%s/%s", patom->CATEGORY, patom->P); |
88 |
+ snprintf(name, sizeof(name), "%s%s/%s%s%s", |
89 |
+ BOLD, patom->CATEGORY, BLUE, patom->P, NORM); |
90 |
label = name; |
91 |
} else if (data->show_filename) { |
92 |
label = buf; |
93 |
@@ -523,25 +530,26 @@ int qgrep_main(int argc, char **argv) |
94 |
|
95 |
while ((i = GETOPT_LONG(QGREP, qgrep, "")) != -1) { |
96 |
switch (i) { |
97 |
- case 'I': args.invert_match = 1; break; |
98 |
+ case 'I': args.invert_match = true; break; |
99 |
case 'i': |
100 |
args.strfunc = strcasestr; |
101 |
reflags |= REG_ICASE; |
102 |
break; |
103 |
- case 'c': args.do_count = 1; break; |
104 |
- case 'l': args.do_list = 1; break; |
105 |
- case 'L': args.do_list = args.invert_list = 1; break; |
106 |
- case 'e': args.do_regex = 1; break; |
107 |
+ case 'c': args.do_count = true; break; |
108 |
+ case 'l': args.do_list = true; break; |
109 |
+ case 'L': args.do_list = args.invert_list = true; break; |
110 |
+ case 'e': args.do_regex = true; break; |
111 |
case 'x': |
112 |
- args.do_regex = 1; |
113 |
+ args.do_regex = true; |
114 |
reflags |= REG_EXTENDED; |
115 |
break; |
116 |
- case 'J': do_installed = 1; break; |
117 |
- case 'E': do_eclass = 1; break; |
118 |
- case 'H': args.show_filename = 1; break; |
119 |
- case 'N': args.show_name = 1; break; |
120 |
- case 's': args.skip_comments = 1; break; |
121 |
- case 'S': args.skip_pattern = optarg; break; |
122 |
+ case 'J': do_installed = true; break; |
123 |
+ case 'E': do_eclass = true; break; |
124 |
+ case 'H': args.show_filename = true; break; |
125 |
+ case 'N': args.show_name = true; break; |
126 |
+ case 's': args.skip_comments = true; break; |
127 |
+ case 'R': args.show_repo = args.show_name = true; break; |
128 |
+ case 'S': args.skip_pattern = optarg; break; |
129 |
case 'B': |
130 |
case 'A': |
131 |
errno = 0; |
132 |
@@ -667,8 +675,9 @@ int qgrep_main(int argc, char **argv) |
133 |
|
134 |
label = NULL; |
135 |
if (args.show_name) { |
136 |
- snprintf(name, sizeof(name), "%.*s", |
137 |
- (int)(strlen(dentry->d_name) - 7), dentry->d_name); |
138 |
+ snprintf(name, sizeof(name), "%s%.*s%s", BLUE, |
139 |
+ (int)(strlen(dentry->d_name) - 7), dentry->d_name, |
140 |
+ NORM); |
141 |
label = name; |
142 |
} else if (args.show_filename) { |
143 |
snprintf(name, sizeof(name), "eclass/%s", dentry->d_name); |