diff options
author | Mark Lodato <lodatom@gmail.com> | 2010-03-07 11:52:46 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-03-08 00:30:44 -0800 |
commit | 55f638bdc6507b3a2ce03290741f592934afaee7 (patch) | |
tree | 8911c25a414e051bf235e5093e8d7229b0b5a9c6 /builtin-grep.c | |
parent | Add GIT_COLOR_BOLD_* and GIT_COLOR_BG_* (diff) | |
download | tgif-55f638bdc6507b3a2ce03290741f592934afaee7.tar.xz |
grep: Colorize filename, line number, and separator
Colorize the filename, line number, and separator in git grep output, as
GNU grep does. The colors are customizable through color.grep.<slot>.
The default is to only color the separator (in cyan), since this gives
the biggest legibility increase without overwhelming the user with
colors. GNU grep also defaults cyan for the separator, but defaults to
magenta for the filename and to green for the line number, as well.
There is one difference from GNU grep: When a binary file matches
without -a, GNU grep does not color the <file> in "Binary file <file>
matches", but we do.
Like GNU grep, if --null is given, the null separators are not colored.
For config.txt, use a a sub-list to describe the slots, rather than
a single paragraph with parentheses, since this is much more readable.
Remove the cast to int for `rm_eo - rm_so` since it is not necessary.
Signed-off-by: Mark Lodato <lodatom@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-grep.c')
-rw-r--r-- | builtin-grep.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/builtin-grep.c b/builtin-grep.c index dcc3d48418..09c2f4913b 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -289,6 +289,7 @@ static int wait_all(void) static int grep_config(const char *var, const char *value, void *cb) { struct grep_opt *opt = cb; + char *color = NULL; switch (userdiff_config(var, value)) { case 0: break; @@ -296,17 +297,24 @@ static int grep_config(const char *var, const char *value, void *cb) default: return 0; } - if (!strcmp(var, "color.grep")) { + if (!strcmp(var, "color.grep")) opt->color = git_config_colorbool(var, value, -1); - return 0; - } - if (!strcmp(var, "color.grep.match")) { + else if (!strcmp(var, "color.grep.filename")) + color = opt->color_filename; + 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.separator")) + color = opt->color_sep; + else + return git_color_default_config(var, value, cb); + if (color) { if (!value) return config_error_nonbool(var); - color_parse(value, var, opt->color_match); - return 0; + color_parse(value, var, color); } - return git_color_default_config(var, value, cb); + return 0; } /* @@ -871,7 +879,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix) opt.regflags = REG_NEWLINE; opt.max_depth = -1; + strcpy(opt.color_filename, ""); + strcpy(opt.color_lineno, ""); strcpy(opt.color_match, GIT_COLOR_BOLD_RED); + strcpy(opt.color_sep, GIT_COLOR_CYAN); opt.color = -1; git_config(grep_config, &opt); if (opt.color == -1) |