[arch-projects] [MKINITCPIO][PATCH 1/2] Fix colors display in some options
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@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
to $(DESTDIR)/usr/share/mkinitcpio to avoid use in mkinicpio -P. Signed-off-by: Sébastien Luttringer <seblu@seblu.net> --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f1114d4..5322ff1 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,8 @@ DIRS = \ /usr/lib/initcpio/udev \ /usr/share/man/man8 \ /usr/share/man/man5 \ - /usr/share/man/man1 + /usr/share/man/man1 \ + /usr/share/mkinitcpio all: doc @@ -44,7 +45,7 @@ install: all install -m644 01-memdisk.rules $(DESTDIR)/usr/lib/initcpio/udev/01-memdisk.rules cp -at $(DESTDIR)/usr/lib/initcpio hooks install - cp -at $(DESTDIR)/etc mkinitcpio.d + install -m644 -t $(DESTDIR)/usr/share/mkinitcpio mkinitcpio.d/* install -m644 man/mkinitcpio.8 $(DESTDIR)/usr/share/man/man8/mkinitcpio.8 install -m644 man/mkinitcpio.conf.5 $(DESTDIR)/usr/share/man/man5/mkinitcpio.conf.5 -- Sébastien "Seblu" Luttringer
On Tue, Feb 05, 2013 at 01:44:29AM +0100, Sébastien Luttringer wrote:
to $(DESTDIR)/usr/share/mkinitcpio to avoid use in mkinicpio -P.
Signed-off-by: Sébastien Luttringer <seblu@seblu.net> ---
Applied locally on top of my allpresets patch.
Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile index f1114d4..5322ff1 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,8 @@ DIRS = \ /usr/lib/initcpio/udev \ /usr/share/man/man8 \ /usr/share/man/man5 \ - /usr/share/man/man1 + /usr/share/man/man1 \ + /usr/share/mkinitcpio
all: doc
@@ -44,7 +45,7 @@ install: all install -m644 01-memdisk.rules $(DESTDIR)/usr/lib/initcpio/udev/01-memdisk.rules
cp -at $(DESTDIR)/usr/lib/initcpio hooks install - cp -at $(DESTDIR)/etc mkinitcpio.d + install -m644 -t $(DESTDIR)/usr/share/mkinitcpio mkinitcpio.d/*
install -m644 man/mkinitcpio.8 $(DESTDIR)/usr/share/man/man8/mkinitcpio.8 install -m644 man/mkinitcpio.conf.5 $(DESTDIR)/usr/share/man/man5/mkinitcpio.conf.5 -- Sébastien "Seblu" Luttringer
On Tue, Feb 05, 2013 at 01:44:28AM +0100, Sébastien Luttringer wrote:
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'.
-k isn't immediately processed, btw. This isn't a valid example. It's potentially true only of -g, -H, -L, and -P.
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@seblu.net> ---
I'm starting to have second thoughts about this patch. It means that you could potentially have color or not based on the order of the flags passed. That is... $ mkinitcpio -L -n # this will be in color $ mkinitcpio -n -L # this will not be in color I tend to think missing out on color for a small number of options versus this inconsistent behavior isn't worthwhile. I could look into some refactoring so that the 4 options I mention above are colorized properly, after arg parsing is done. It's probably equally wrong to be doing work straight out of arg parsing.
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
On Tue, Feb 5, 2013 at 2:01 AM, Dave Reisner <d@falconindy.com> wrote:
On Tue, Feb 05, 2013 at 01:44:28AM +0100, Sébastien Luttringer wrote:
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'.
-k isn't immediately processed, btw. This isn't a valid example. It's potentially true only of -g, -H, -L, and -P.
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@seblu.net> ---
I'm starting to have second thoughts about this patch. It means that you could potentially have color or not based on the order of the flags passed. That is...
$ mkinitcpio -L -n # this will be in color $ mkinitcpio -n -L # this will not be in color
I tend to think missing out on color for a small number of options versus this inconsistent behavior isn't worthwhile. I could look into some refactoring so that the 4 options I mention above are colorized properly, after arg parsing is done. It's probably equally wrong to be doing work straight out of arg parsing. I agree. Re-factoring is a better solution!
-- Sébastien "Seblu" Luttringer https://www.seblu.net GPG: 0x2072D77A
participants (2)
-
Dave Reisner
-
Sébastien Luttringer