ls: don't output any colors with TERM=dumb
No binary (build failed)
—
(log yok)
| @@ -1145,11 +1145,15 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |
| #if ENABLE_FEATURE_LS_COLOR | |
| /* set G_show_color = 1/0 */ | |
| - | if (ENABLE_FEATURE_LS_COLOR_IS_DEFAULT && isatty(STDOUT_FILENO)) { |
| + | if (ENABLE_FEATURE_LS_COLOR_IS_DEFAULT && !is_TERM_dumb()) { |
| char *p = getenv("LS_COLORS"); | |
| /* LS_COLORS is unset, or (not empty && not "none") ? */ | |
| - | if (!p || (p[0] && strcmp(p, "none") != 0)) |
| - | G_show_color = 1; |
| + | if (!p || (p[0] && strcmp(p, "none") != 0)) { |
| + | if (isatty(STDOUT_FILENO)) { |
| + | /* check isatty() last because it's expensive (syscall) */ |
| + | G_show_color = 1; |
| + | } |
| + | } |
| } | |
| if (opt & OPT_color) { | |
| if (color_opt[0] == 'n') | |
| @@ -1158,7 +1162,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |
| case 3: | |
| case 4: | |
| case 5: | |
| - | if (isatty(STDOUT_FILENO)) { |
| + | if (!is_TERM_dumb() && isatty(STDOUT_FILENO)) { |
| case 0: | |
| case 1: | |
| case 2: | |
| @@ -1773,6 +1773,7 @@ extern void print_login_issue(const char *issue_file, const char *tty) FAST_FUNC | |
| extern void print_login_prompt(void) FAST_FUNC; | |
| char *xmalloc_ttyname(int fd) FAST_FUNC RETURNS_MALLOC; | |
| + | int is_TERM_dumb(void) FAST_FUNC; |
| /* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */ | |
| int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FUNC; | |
| int get_terminal_width(int fd) FAST_FUNC; | |
| @@ -303,6 +303,12 @@ int FAST_FUNC get_terminal_width(int fd) | |
| return width; | |
| } | |
| + | int FAST_FUNC is_dumb_term(void) |
| + | { |
| + | char *term = getenv("TERM"); |
| + | return term && strcmp(term, "dumb") == 0; |
| + | } |
| + | |
| int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) | |
| { | |
| return tcsetattr(STDIN_FILENO, TCSANOW, tp); | |