mirror of
https://github.com/systemd/systemd.git
synced 2025-03-11 20:58:27 +03:00
Merge pull request #30362 from mrc0mmand/cat-highlight-directives
shared: highlight directives when dumping configs
This commit is contained in:
commit
2b2f192a0e
@ -35,7 +35,7 @@ int verb_cat_config(int argc, char *argv[], void *userdata) {
|
||||
} else
|
||||
t = *arg;
|
||||
|
||||
r = conf_files_cat(arg_root, t, arg_cat_flags);
|
||||
r = conf_files_cat(arg_root, t, arg_cat_flags | CAT_FORMAT_HAS_SECTIONS);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ static int cat_file(const char *filename, bool newline, CatFlags flags) {
|
||||
break;
|
||||
|
||||
LineType line_type = classify_line_type(line, flags);
|
||||
if (flags & CAT_TLDR) {
|
||||
if (FLAGS_SET(flags, CAT_TLDR)) {
|
||||
if (line_type == LINE_SECTION) {
|
||||
/* The start of a section, let's not print it yet. */
|
||||
free_and_replace(section, line);
|
||||
@ -236,6 +236,28 @@ static int cat_file(const char *filename, bool newline, CatFlags flags) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Highlight the left side (directive) of a Foo=bar assignment */
|
||||
if (FLAGS_SET(flags, CAT_FORMAT_HAS_SECTIONS) && line_type == LINE_NORMAL) {
|
||||
const char *p = strchr(line, '=');
|
||||
if (p) {
|
||||
_cleanup_free_ char *highlighted = NULL, *directive = NULL;
|
||||
|
||||
directive = strndup(line, p - line);
|
||||
if (!directive)
|
||||
return log_oom();
|
||||
|
||||
highlighted = strjoin(ansi_highlight_green(),
|
||||
directive,
|
||||
"=",
|
||||
ansi_normal(),
|
||||
p + 1);
|
||||
if (!highlighted)
|
||||
return log_oom();
|
||||
|
||||
free_and_replace(line, highlighted);
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s%s%s\n",
|
||||
line_type == LINE_SECTION ? ansi_highlight_cyan() :
|
||||
line_type == LINE_COMMENT ? ansi_highlight_grey() :
|
||||
|
Loading…
x
Reference in New Issue
Block a user