From 9cc52bb17614497dfc5eb1de503ca088f4e32189 Mon Sep 17 00:00:00 2001 From: Ulrich Müller Date: Fri, 28 Oct 2011 23:43:52 +0000 Subject: New global option --colour=. svn path=/trunk/; revision=854 --- ChangeLog | 10 ++++++++++ NEWS | 1 + bin/eselect.in | 40 +++++++++++++++++++++++----------------- man/eselect.1 | 16 +++++++++++++--- misc/eselect.bashcomp | 2 +- 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 36043cd..39e1460 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-10-29 Ulrich Mueller + + * bin/eselect.in: New option --colour=, similar to + the same option in emerge and ls commands. Spelling --color is + recognised too. + (es_do_list_options): Update accordingly. + (ESELECT_OPTIONS): Remove unused global variable. + * man/eselect.1: Document the --colour option. + * misc/eselect.bashcomp (_eselect): Update. + 2011-10-27 Ulrich Mueller * modules/news.eselect (do_list): Display read/unread flags as one diff --git a/NEWS b/NEWS index 0a64a23..ed8c49f 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ ChangeLog file for a more detailed listing of changes/bug fixes. New features: - The profile module supports profiles in overlays (bug #265264). - Changed output formatting in news module (bug #388233). + - New global option --colour=. 1.2.18: Bug fixes: diff --git a/bin/eselect.in b/bin/eselect.in index 0b2b7e1..4b096e5 100755 --- a/bin/eselect.in +++ b/bin/eselect.in @@ -41,9 +41,6 @@ ESELECT_PROGRAM_NAME="eselect" ESELECT_BINARY_NAME="$0" ESELECT_KILL_TARGET="$$" -# Global options -ESELECT_OPTIONS="" - # Support variables for Gentoo Prefix EPREFIX="@EPREFIX@" EROOT="${ROOT}${EPREFIX}" @@ -112,8 +109,9 @@ es_do_version() { # Display all recognized global options es_do_list_options() { write_list_start "Global options:" - write_kv_list_entry "--brief" "Make output shorter" - write_kv_list_entry "--no-color,--no-colour" "Disable coloured output" + write_kv_list_entry "--brief" "Make output shorter" + write_kv_list_entry "--colour=" \ + "Enable or disable colour output (default 'auto')" } # es_do_list_modules @@ -124,14 +122,6 @@ es_do_list_modules() { ### main code ### -# enable colour output and get width of terminal iff stdout is a tty -if [[ -t 1 ]]; then - colours - init_columns -else - nocolours -fi - # figure out what the action is. we need to know whether we're # invoked as a something-config/something-update. action="" @@ -161,12 +151,19 @@ if [[ -z ${action} ]] && [[ -n ${1##--} ]]; then while [[ ${1##--} != "$1" ]]; do case ${1##--} in brief) - ESELECT_OPTIONS="${ESELECT_OPTIONS} brief" set_output_mode brief ;; - no-colour|no-color) - ESELECT_OPTIONS="${ESELECT_OPTIONS} no-colour" - nocolours + colour=*|color=*|colour|color) + # accept all arguments that are valid for ls or emerge + case ${1#*=} in + yes|y|always|force|$1) colour=yes ;; + no|n|never|none) colour=no ;; + auto|tty|if-tty) colour="" ;; + *) die -q "Invalid argument for ${1%%=*} option" ;; + esac + ;; + no-colour|no-color) # legacy option + colour=no ;; help|version) action=${1##--} @@ -183,6 +180,15 @@ if [[ -z ${action} ]] && [[ -n ${1##--} ]]; then fi fi +# enable colour output and get width of terminal iff stdout is a tty +if [[ -t 1 ]]; then + if [[ ${colour} = no ]]; then nocolours; else colours; fi + init_columns +else + if [[ ${colour} = yes ]]; then colours; else nocolours; fi +fi +unset colour + if [[ -n ${action} ]]; then if is_function "es_do_${action//-/_}"; then [[ $# -gt 0 ]] && die -q "Too many parameters" diff --git a/man/eselect.1 b/man/eselect.1 index 9633ab6..c50f417 100644 --- a/man/eselect.1 +++ b/man/eselect.1 @@ -2,7 +2,7 @@ .\" Distributed under the terms of the GNU General Public License v2 .\" $Id$ .\" -.TH ESELECT 1 "August 2009" "Gentoo Linux" eselect +.TH ESELECT 1 "October 2011" "Gentoo Linux" eselect .SH NAME eselect \- Gentoo's multi\-purpose configuration and management tool .SH SYNOPSIS @@ -20,8 +20,18 @@ that care for individual administrative tasks. Set brief output mode, for use as input to other programs. (This is an experimental feature.) .TP -.BR \-\-no-color ", " \-\-no-colour -Disable coloured output. +.BI \-\-color= "mode, " \-\-colour= mode +Enable or disable colour output. +.I mode +can be +.BR yes , +.BR no , +or +.BR auto . +The default is +.BR auto , +for which colour output is enabled only if standard output is +connected to a terminal. .SH BUILT-INS .TP .B help diff --git a/misc/eselect.bashcomp b/misc/eselect.bashcomp index 32e525d..c831c9d 100644 --- a/misc/eselect.bashcomp +++ b/misc/eselect.bashcomp @@ -8,7 +8,7 @@ _eselect() { local cur sedcmd2 sedcmd3 possibles - local options="--brief --no-colour" + local options="--brief --colour=" COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" sedcmd2='s/^ \([[:alnum:]-][[:alnum:]_-]*\)[[:space:],].*$/\1/p' -- cgit v1.2.3-65-gdbad