summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/config.txt6
-rw-r--r--builtin-grep.c9
-rw-r--r--grep.c11
-rw-r--r--grep.h3
4 files changed, 27 insertions, 2 deletions
diff --git a/Documentation/config.txt b/Documentation/config.txt
index d6e4a3e0cc..88e1d49d6e 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -688,12 +688,18 @@ color.grep.<slot>::
part of the line to use the specified color, and is one of
+
--
+`context`;;
+ non-matching text in context lines (when using `-A`, `-B`, or `-C`)
`filename`;;
filename prefix (when not using `-h`)
+`function`;;
+ function name lines (when using `-p`)
`linenumber`;;
line number prefix (when using `-n`)
`match`;;
matching text
+`selected`;;
+ non-matching text in selected lines
`separator`;;
separators between fields on a line (`:`, `-`, and `=`)
and between hunks (`--`)
diff --git a/builtin-grep.c b/builtin-grep.c
index 09c2f4913b..d455176f78 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -299,12 +299,18 @@ static int grep_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "color.grep"))
opt->color = git_config_colorbool(var, value, -1);
+ else if (!strcmp(var, "color.grep.context"))
+ color = opt->color_context;
else if (!strcmp(var, "color.grep.filename"))
color = opt->color_filename;
+ else if (!strcmp(var, "color.grep.function"))
+ color = opt->color_function;
else if (!strcmp(var, "color.grep.linenumber"))
color = opt->color_lineno;
else if (!strcmp(var, "color.grep.match"))
color = opt->color_match;
+ else if (!strcmp(var, "color.grep.selected"))
+ color = opt->color_selected;
else if (!strcmp(var, "color.grep.separator"))
color = opt->color_sep;
else
@@ -879,9 +885,12 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
opt.regflags = REG_NEWLINE;
opt.max_depth = -1;
+ strcpy(opt.color_context, "");
strcpy(opt.color_filename, "");
+ strcpy(opt.color_function, "");
strcpy(opt.color_lineno, "");
strcpy(opt.color_match, GIT_COLOR_BOLD_RED);
+ strcpy(opt.color_selected, "");
strcpy(opt.color_sep, GIT_COLOR_CYAN);
opt.color = -1;
git_config(grep_config, &opt);
diff --git a/grep.c b/grep.c
index 42e915d762..b641305ff6 100644
--- a/grep.c
+++ b/grep.c
@@ -529,6 +529,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
const char *name, unsigned lno, char sign)
{
int rest = eol - bol;
+ char *line_color = NULL;
if (opt->pre_context || opt->post_context) {
if (opt->last_shown == 0) {
@@ -560,12 +561,18 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
int ch = *eol;
int eflags = 0;
+ if (sign == ':')
+ line_color = opt->color_selected;
+ else if (sign == '-')
+ line_color = opt->color_context;
+ else if (sign == '=')
+ line_color = opt->color_function;
*eol = '\0';
while (next_match(opt, bol, eol, ctx, &match, eflags)) {
if (match.rm_so == match.rm_eo)
break;
- opt->output(opt, bol, match.rm_so);
+ output_color(opt, bol, match.rm_so, line_color);
output_color(opt, bol + match.rm_so,
match.rm_eo - match.rm_so,
opt->color_match);
@@ -575,7 +582,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
}
*eol = ch;
}
- opt->output(opt, bol, rest);
+ output_color(opt, bol, rest, line_color);
opt->output(opt, "\n", 1);
}
diff --git a/grep.h b/grep.h
index 36919ee217..2c4bdaca82 100644
--- a/grep.h
+++ b/grep.h
@@ -84,9 +84,12 @@ struct grep_opt {
int color;
int max_depth;
int funcname;
+ char color_context[COLOR_MAXLEN];
char color_filename[COLOR_MAXLEN];
+ char color_function[COLOR_MAXLEN];
char color_lineno[COLOR_MAXLEN];
char color_match[COLOR_MAXLEN];
+ char color_selected[COLOR_MAXLEN];
char color_sep[COLOR_MAXLEN];
int regflags;
unsigned pre_context;