Skip to content

Commit 765a745

Browse files
committed
crontab: switch off colors if NO_COLOR is set
1 parent 6275289 commit 765a745

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎man/crontab.1‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ not set by the user, the
114114
.I /tmp
115115
directory is used.
116116
.PP
117+
When listing a crontab on a terminal the output will be colorized unless
118+
an environment variable
119+
.I NO_COLOR
120+
is set.
121+
.PP
117122
.SH "OPTIONS"
118123
.TP
119124
.B "\-u"

‎src/crontab.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ static void list_cmd(void) {
419419
char n[MAX_FNAME];
420420
FILE *f;
421421
int ch;
422-
const int is_tty = isatty(STDOUT);
422+
const int colorize = isatty(STDOUT) && getenv("NO_COLOR") == NULL;
423423
int new_line = 1;
424424
int in_comment = 0;
425425

@@ -440,7 +440,7 @@ static void list_cmd(void) {
440440
*/
441441
Set_LineNum(1);
442442
while (EOF != (ch = get_char(f))) {
443-
if (is_tty) {
443+
if (colorize) {
444444
if (!in_comment && new_line && ch == '#') {
445445
in_comment = 1;
446446
fputs(COMMENT_COLOR, stdout);
@@ -454,7 +454,7 @@ static void list_cmd(void) {
454454
new_line = ch == '\n';
455455
}
456456
/* no new line at EOF */
457-
if (is_tty && !new_line) {
457+
if (colorize && !new_line) {
458458
putchar('\n');
459459
fputs(ERROR_COLOR "No end-of-line character at the end of file"
460460
RESET_COLOR, stdout);

0 commit comments

Comments
 (0)