[pacman-dev] [PATCH] makepkg: check explicitly if the terminal supports colors

Cedric Staniewski cedric at gmx.ca
Thu Jun 24 06:01:52 EDT 2010


Currently, makepkg aborts when colors are enabled (the default) and it
runs in a terminal that does not support it, because tput returns a
non-zero exit code.
---

Another solution would be appending "|| true" to each tput line or disabling errexit in this section, so we get at
least bold. Not sure if this is a real improvement, when the color option makes
text bold but not colored.

scripts/makepkg.sh.in |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index dbc4047..1795b54 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1620,8 +1620,11 @@ fi
 PACMAN=${PACMAN:-pacman}
 
 # check if messages are to be printed using color
+# It is needed to explicitly check if the terminal supports colors, because
+# otherwise, tput will return a non-zero exit code that stops makepkg due to
+# bash's errexit option.
 unset ALL_OFF BOLD BLUE GREEN RED YELLOW
-if [[ -t 2 && ! $USE_COLOR = "n" && $(check_buildenv color) = "y" ]]; then
+if [[ -t 2 && ! $USE_COLOR = "n" && $(check_buildenv color) = "y" ]] && tput setaf 0 &>/dev/null; then
 	ALL_OFF="$(tput sgr0)"
 	BOLD="$(tput bold)"
 	BLUE="${BOLD}$(tput setaf 4)"
-- 
1.7.1



More information about the pacman-dev mailing list