From b80204f59953b570a790ffa37e3d90271bebbf84 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Thu, 3 Jan 2019 03:32:05 +0100 Subject: [PATCH] Fix `tmux` text being always red `tmux` (https://github.com/tmux/tmux/wiki) is a terminal multiplexer, like `screen`. It spawns its terminals with `argv[0]` prefixed with a '-', thus breaking `stderred`'s early return on `bash` encounter. This leads to normal text being always red. When `PROGRAM_NAME` matches the '-%s' format pattern, treat it as a shell and return early. Refer to https://github.com/tmux/tmux/blob/c9d482ab489d5d57d481858091608ee1b32e46ab/window.c#L993 and to https://github.com/tmux/tmux/commit/22d1b9412e52c98cbdf52a3a5185a416c6d26c64. Fixes https://github.com/sickill/stderred/issues/52 --- src/stderred.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/stderred.c b/src/stderred.c index 477578e..2eac2f3 100644 --- a/src/stderred.c +++ b/src/stderred.c @@ -38,6 +38,8 @@ bool is_valid_env = false; __attribute__((constructor)) void init() { if (!strcmp("bash", PROGRAM_NAME)) return; + /* "tmux" spawns subshells with argv[0] prefixed with a '-', e.g. "-bash" */ + if (PROGRAM_NAME && PROGRAM_NAME[0] == '-' && PROGRAM_NAME[1] != '\0') return; if (!isatty(STDERR_FILENO)) return; char *blacklist;