From c7f5fb40c46b8c99ddc93fbc1df2987e178e0124 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Mon, 10 Feb 2014 12:37:39 +0100 Subject: [PATCH] zhs/rc: Autodetect coloredstderr. --- .gitignore | 1 + zsh/rc | 39 ++++++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index d02c4f1..c08e6d5 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ # Ignore unimportant files. /crontab.d/crontab.dotfiles-vim /crontab.d/crontab.jobs +/zsh/libcoloredstderr.so diff --git a/zsh/rc b/zsh/rc index 8691679..876bfc7 100644 --- a/zsh/rc +++ b/zsh/rc @@ -905,19 +905,32 @@ if [[ $TERM != dumb && $TERM != linux && -z $STY && -z $TMUX ]]; then fi fi -# Colorize stderr in bold red. Very useful when looking for errors. Thanks to -# http://gentoo-wiki.com/wiki/Zsh for the basic script and Mikachu in #zsh on -# Freenode (2010-03-07 04:03 CET) for some improvements (-r, printf). It's not -# yet perfect and doesn't work with su and git for example, but it can handle -# most interactive output quite well (even with no trailing new line) and in -# cases it doesn't work, the E alias can be used as workaround. -# -# Moved in the "run commands" section to prevent one unnecessary zsh process -# when starting GNU screen/tmux (see above). -exec 2>>(while read -r -k -u 0 line; do - printf '\e[91m%s\e[0m' "$line" - print -n $'\0' -done &) +# Colorize stderr in bold red. Very useful when looking for errors. +if [[ $LD_PRELOAD != *libcoloredstderr.so* ]]; then + # coloredstderr found, use it. + if [[ -f ~/.zsh/libcoloredstderr.so ]]; then + export LD_PRELOAD="$HOME/.zsh/libcoloredstderr.so:$LD_PRELOAD" + export COLORED_STDERR_FDS=2, + export COLORED_STDERR_PRE=$'\033[91m' # bright red + export COLORED_STDERR_IGNORED_BINARIES=/usr/bin/tset + # Use the fallback solution. + # + # Thanks to http://gentoo-wiki.com/wiki/Zsh for the basic script and + # Mikachu in #zsh on Freenode (2010-03-07 04:03 CET) for some improvements + # (-r, printf). It's not yet perfect and doesn't work with su and git for + # example, but it can handle most interactive output quite well (even with + # no trailing new line) and in cases it doesn't work, the E alias can be + # used as workaround. + # + # Moved in the "run commands" section to prevent one unnecessary zsh + # process when starting GNU screen/tmux (see above). + else + exec 2>>(while read -r -k -u 0 line; do + printf '\e[91m%s\e[0m' "$line" + print -n $'\0' + done &) + fi +fi # Display possible log messages from ~/.xinitrc (if `xmessage` wasn't # installed). No race condition as xinitrc has finished before a shell is -- 2.45.2