[arch-projects] [MKINITCPIO][PATCH 4/4] Fix colors display in some options
Sébastien Luttringer
seblu at seblu.net
Mon Feb 4 12:44:02 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..d58a71a 100644
--- a/functions
+++ b/functions
@@ -693,4 +693,8 @@ try_enable_color() {
fi
}
+disable_colors() {
+ unset _color_none _color_bold _color_blue _color_green _color_red _color_yellow
+}
+
# vim: set ft=sh ts=4 sw=4 et:
diff --git a/mkinitcpio b/mkinitcpio
index fb07001..dca3a06 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -357,6 +357,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
@@ -394,7 +398,8 @@ while :; do
shift
_optpreset=("$1") ;;
-n|--nocolor)
- _optcolor=0 ;;
+ _optcolor=0
+ disable_colors ;;
-v|--verbose)
_optquiet=0 ;;
-S|--skiphooks)
@@ -427,10 +432,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