[arch-projects] [MKINITCPIO][PATCH 1/2] Fix colors display in some options

Sébastien Luttringer seblu at seblu.net
Mon Feb 4 19:44:28 EST 2013


Colors initialization was called after arg parsing. This disallow error messages
and options called directly from arg parser to use colors.
By example, call `mkinitcpio -k toto' or `mkinitcpio -L'.

This patch initialize colors when terminal is able to support it but disable it
if users don't wants it (with -n).

Signed-off-by: Sébastien Luttringer <seblu at seblu.net>
---
 functions  |  4 ++++
 mkinitcpio | 11 ++++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/functions b/functions
index 4df91bc..b747f40 100644
--- a/functions
+++ b/functions
@@ -693,4 +693,8 @@ try_enable_color() {
     fi
 }
 
+disable_colors() {
+    unset "${!_color_@}"
+}
+
 # vim: set ft=sh ts=4 sw=4 et:
diff --git a/mkinitcpio b/mkinitcpio
index 9802fd5..0863f3f 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -348,6 +348,10 @@ parseopts "$_opt_short" "${_opt_long[@]}" -- "$@" || exit 1
 set -- "${OPTRET[@]}"
 unset _opt_short _opt_long OPTRET
 
+if [[ -t 1 ]]; then
+    try_enable_color
+fi
+
 while :; do
     case $1 in
         # --add remains for backwards compat
@@ -380,7 +384,8 @@ while :; do
             shift
             _optpreset=$1 ;;
         -n|--nocolor)
-            _optcolor=0 ;;
+            _optcolor=0
+            disable_colors ;;
         -v|--verbose)
             _optquiet=0 ;;
         -S|--skiphooks)
@@ -413,10 +418,6 @@ while :; do
     shift
 done
 
-if [[ -t 1 ]] && (( _optcolor )); then
-    try_enable_color
-fi
-
 # insist that /proc and /dev be mounted (important for chroots)
 # NOTE: avoid using mountpoint for this -- look for the paths that we actually
 # use in mkinitcpio. Avoids issues like FS#26344.
-- 
Sébastien "Seblu" Luttringer



More information about the arch-projects mailing list