This is a diff of crontab.c providing a color change for comment lines for the `crontab -l` output. You can see a demo with the provided screenshot attached to this message too.
Note that the DEBIAN_HEADERS are not colorized. If you're interested, I can patch the code for this part too. I used space indentation only because the file mixes tabs and spaces indentation so I didn't know what was the right choice. I saw in the documentation that, in the future, cronie could be used instead of the vixie cron. Perhaps I should push such a feature in cronie instead? (Perhaps it's currently available in cronie, I didn't check.) -- Stéphane
--- crontab.c.orig 2016-02-18 01:12:36.253608497 +0100 +++ crontab.c 2016-02-18 01:18:31.655518325 +0100 @@ -33,6 +33,7 @@ #include <fcntl.h> #include <libgen.h> #include <signal.h> +#include <stdio.h> #include <sys/file.h> #include <sys/stat.h> #ifdef USE_UTIMES @@ -48,6 +49,10 @@ #define NHEADER_LINES 3 +#define COMMENT_COLOR "\x1B[34m" +#define RESET_COLOR "\033[0m" + + enum opt_t { opt_unknown, opt_list, opt_delete, opt_edit, opt_replace }; #if DEBUGGING @@ -302,6 +307,7 @@ char n[MAX_FNAME]; FILE *f; int ch; + int new_line = 1; #ifdef DEBIAN int x; char *ctnh; @@ -345,8 +351,17 @@ } } #endif - while (EOF != (ch = get_char(f))) - putchar(ch); + while (EOF != (ch = get_char(f))){ + if(new_line){ + if(ch == '#'){ + printf(COMMENT_COLOR); + }else{ + printf(RESET_COLOR); + } + } + putchar(ch); + new_line = ch == '\n'; + } fclose(f); }
signature.asc
Description: OpenPGP digital signature