[pacman-dev] [PATCH 0/7] Add color to script output
With the advent of the pacman color patches, I figured that I would add color output to the rest of the scripts in pacman. This is a kind of not-3am v3 for the previous patch that I sent in. William Giokas (7): script: Add color to library/output_format.sh makepkg: use output_format, add --quiet option script: add color to pacman-db-upgrade scripts: add color to pacman-key scripts: add color to pacman-optimize scripts: add color to pkgdelta scripts: add color to repo-add doc/makepkg.8.txt | 4 ++++ doc/pacman-key.8.txt | 3 +++ doc/repo-add.8.txt | 3 +++ scripts/library/README | 6 +++++- scripts/library/output_format.sh | 18 +++++++++++++----- scripts/library/term_colors.sh | 21 +++++++++++++++++++++ scripts/makepkg.sh.in | 35 +++++++---------------------------- scripts/pacman-db-upgrade.sh.in | 11 ++++++++++- scripts/pacman-key.sh.in | 8 ++++++-- scripts/pacman-optimize.sh.in | 11 ++++++++++- scripts/pkgdelta.sh.in | 6 ++++++ scripts/repo-add.sh.in | 5 +++++ 12 files changed, 93 insertions(+), 38 deletions(-) create mode 100644 scripts/library/term_colors.sh -- 1.8.2.rc1.24.g06d67b8
Use the same colors as makepkg when printing messages using the functions in output_format.sh. Signed-off-by: William Giokas <1007380@gmail.com> --- scripts/library/README | 6 +++++- scripts/library/output_format.sh | 18 +++++++++++++----- scripts/library/term_colors.sh | 21 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 scripts/library/term_colors.sh diff --git a/scripts/library/README b/scripts/library/README index 0fa0f84..5f2961c 100644 --- a/scripts/library/README +++ b/scripts/library/README @@ -6,7 +6,7 @@ Provides basic output formatting functions with levels 'msg', 'msg2', 'warning' and 'error'. The 'msg' amd 'msg2' functions print to stdout and can be silenced by defining 'QUIET'. The 'warning' and 'error' functions print to stderr with the appropriate prefix added to the -message. +message. Also includes optional color output. parseopts.sh: A getopt_long-like parser which portably supports longopts and shortopts @@ -39,3 +39,7 @@ as mawk or busybox awk. size_to_human.sh: The reverse of human_to_size, this function takes an integer byte size and prints its in human readable format, with SI prefixes (e.g. MiB, TiB). + +term_colors.sh +Set the terminal colors for the common message formats. Uses the variable +`USE_COLOR` to determine when to be used. diff --git a/scripts/library/output_format.sh b/scripts/library/output_format.sh index 9e890e7..5deea50 100644 --- a/scripts/library/output_format.sh +++ b/scripts/library/output_format.sh @@ -1,21 +1,29 @@ +# Common message formats + +plain() { + (( QUIET )) && return + local mesg=$1; shift + printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 +} + msg() { (( QUIET )) && return local mesg=$1; shift - printf "==> ${mesg}\n" "$@" >&1 + printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1 } msg2() { (( QUIET )) && return local mesg=$1; shift - printf " -> ${mesg}\n" "$@" >&1 + printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1 } warning() { local mesg=$1; shift - printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2 + printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } error() { local mesg=$1; shift - printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2 -} \ No newline at end of file + printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 +} diff --git a/scripts/library/term_colors.sh b/scripts/library/term_colors.sh new file mode 100644 index 0000000..a675247 --- /dev/null +++ b/scripts/library/term_colors.sh @@ -0,0 +1,21 @@ +# check if messages are to be printed using color +unset ALL_OFF BOLD BLUE GREEN RED YELLOW +if [[ -t 2 && ! $USE_COLOR = "n" ]]; then + # prefer terminal safe colored and bold text when tput is supported + if tput setaf 0 &>/dev/null; then + ALL_OFF="$(tput sgr0)" + BOLD="$(tput bold)" + BLUE="${BOLD}$(tput setaf 4)" + GREEN="${BOLD}$(tput setaf 2)" + RED="${BOLD}$(tput setaf 1)" + YELLOW="${BOLD}$(tput setaf 3)" + else + ALL_OFF="\e[1;0m" + BOLD="\e[1;1m" + BLUE="${BOLD}\e[1;34m" + GREEN="${BOLD}\e[1;32m" + RED="${BOLD}\e[1;31m" + YELLOW="${BOLD}\e[1;33m" + fi +fi +readonly ALL_OFF BOLD BLUE GREEN RED YELLOW -- 1.8.2.rc1.24.g06d67b8
output_format.sh is now much the same as the original message subroutines, so just use m4_include to pull that in. This also adds a `(( QUIET )) && return` to the output format section, allowing for a --quiet switch to suppress some output. Signed-off-by: William Giokas <1007380@gmail.com> --- doc/makepkg.8.txt | 4 ++++ scripts/makepkg.sh.in | 35 +++++++---------------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt index 498c79b..94343b5 100644 --- a/doc/makepkg.8.txt +++ b/doc/makepkg.8.txt @@ -118,6 +118,10 @@ Options Read the package script `buildscript` instead of the `PKGBUILD` default; see linkman:PKGBUILD[5]. +*-q, \--quiet*:: + Suppress makepkg messages. Does not change printing of commands in + PKGBUILD, error or warning messages. + *-r, \--rmdeps*:: Upon successful build, remove any dependencies installed by makepkg during dependency auto-resolution and installation when using `-s`. diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index bd29d73..a90efe5 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -79,6 +79,7 @@ CHECKFUNC=0 PKGFUNC=0 PKGVERFUNC=0 SPLITPKG=0 +QUIET=0 PKGLIST=() SIGNPKG='' @@ -92,31 +93,7 @@ shopt -s extglob ### SUBROUTINES ### -plain() { - local mesg=$1; shift - printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -msg() { - local mesg=$1; shift - printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -msg2() { - local mesg=$1; shift - printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -warning() { - local mesg=$1; shift - printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -error() { - local mesg=$1; shift - printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - +m4_include(library/output_format.sh) ## # Special exit call for traps, Don't print any error messages when inside, @@ -2404,6 +2381,7 @@ usage() { printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n" printf -- "$(gettext " -o, --nobuild Download and extract files only")\n" printf -- "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT" + printf -- "$(gettext " -q, --quiet Suppress some makepkg output")\n" printf -- "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")\n" printf -- "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")\n" printf -- "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman" @@ -2454,11 +2432,11 @@ fi ARGLIST=("$@") # Parse Command Line Options. -OPT_SHORT="AcdefFghiLmop:rRsSV" +OPT_SHORT="AcdefFghiLmop:qrRsSV" OPT_LONG=('allsource' 'asroot' 'check' 'clean' 'config:' 'force' 'geninteg' 'help' 'holdver' 'ignorearch' 'install' 'key:' 'log' 'nobuild' 'nocolor' - 'nocheck' 'nodeps' 'noextract' 'nosign' 'pkg:' 'repackage' 'rmdeps' - 'skipchecksums' 'skipinteg' 'skippgpcheck' 'skippgpcheck' 'sign' + 'nocheck' 'nodeps' 'noextract' 'nosign' 'pkg:' 'quiet' 'repackage' + 'rmdeps' 'skipchecksums' 'skipinteg' 'skippgpcheck' 'skippgpcheck' 'sign' 'source' 'syncdeps' 'version') # Pacman Options @@ -2500,6 +2478,7 @@ while true; do -o|--nobuild) NOBUILD=1 ;; -p) shift; BUILDFILE=$1 ;; --pkg) shift; IFS=, read -ra p <<<"$1"; PKGLIST+=("${p[@]}"); unset p ;; + -q|--quiet) QUIET=1 ;; -r|--rmdeps) RMDEPS=1 ;; -R|--repackage) REPKG=1 ;; --skipchecksums) SKIPCHECKSUMS=1 ;; -- 1.8.2.rc1.24.g06d67b8
On 03/03/13 07:50, William Giokas wrote:
output_format.sh is now much the same as the original message subroutines, so just use m4_include to pull that in. This also adds a `(( QUIET )) && return` to the output format section, allowing for a --quiet switch to suppress some output.
Signed-off-by: William Giokas <1007380@gmail.com> ---
Rejected. All amkepkg's messages got to stderr, so it can not use output_format.
doc/makepkg.8.txt | 4 ++++ scripts/makepkg.sh.in | 35 +++++++---------------------------- 2 files changed, 11 insertions(+), 28 deletions(-)
diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt index 498c79b..94343b5 100644 --- a/doc/makepkg.8.txt +++ b/doc/makepkg.8.txt @@ -118,6 +118,10 @@ Options Read the package script `buildscript` instead of the `PKGBUILD` default; see linkman:PKGBUILD[5].
+*-q, \--quiet*:: + Suppress makepkg messages. Does not change printing of commands in + PKGBUILD, error or warning messages. + *-r, \--rmdeps*:: Upon successful build, remove any dependencies installed by makepkg during dependency auto-resolution and installation when using `-s`. diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index bd29d73..a90efe5 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -79,6 +79,7 @@ CHECKFUNC=0 PKGFUNC=0 PKGVERFUNC=0 SPLITPKG=0 +QUIET=0 PKGLIST=() SIGNPKG=''
@@ -92,31 +93,7 @@ shopt -s extglob
### SUBROUTINES ###
-plain() { - local mesg=$1; shift - printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -msg() { - local mesg=$1; shift - printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -msg2() { - local mesg=$1; shift - printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -warning() { - local mesg=$1; shift - printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -error() { - local mesg=$1; shift - printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - +m4_include(library/output_format.sh)
## # Special exit call for traps, Don't print any error messages when inside, @@ -2404,6 +2381,7 @@ usage() { printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n" printf -- "$(gettext " -o, --nobuild Download and extract files only")\n" printf -- "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT" + printf -- "$(gettext " -q, --quiet Suppress some makepkg output")\n" printf -- "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")\n" printf -- "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")\n" printf -- "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman" @@ -2454,11 +2432,11 @@ fi ARGLIST=("$@")
# Parse Command Line Options. -OPT_SHORT="AcdefFghiLmop:rRsSV" +OPT_SHORT="AcdefFghiLmop:qrRsSV" OPT_LONG=('allsource' 'asroot' 'check' 'clean' 'config:' 'force' 'geninteg' 'help' 'holdver' 'ignorearch' 'install' 'key:' 'log' 'nobuild' 'nocolor' - 'nocheck' 'nodeps' 'noextract' 'nosign' 'pkg:' 'repackage' 'rmdeps' - 'skipchecksums' 'skipinteg' 'skippgpcheck' 'skippgpcheck' 'sign' + 'nocheck' 'nodeps' 'noextract' 'nosign' 'pkg:' 'quiet' 'repackage' + 'rmdeps' 'skipchecksums' 'skipinteg' 'skippgpcheck' 'skippgpcheck' 'sign' 'source' 'syncdeps' 'version')
# Pacman Options @@ -2500,6 +2478,7 @@ while true; do -o|--nobuild) NOBUILD=1 ;; -p) shift; BUILDFILE=$1 ;; --pkg) shift; IFS=, read -ra p <<<"$1"; PKGLIST+=("${p[@]}"); unset p ;; + -q|--quiet) QUIET=1 ;; -r|--rmdeps) RMDEPS=1 ;; -R|--repackage) REPKG=1 ;; --skipchecksums) SKIPCHECKSUMS=1 ;;
On Mon, Mar 04, 2013 at 03:11:02AM +1000, Allan McRae wrote:
On 03/03/13 07:50, William Giokas wrote:
output_format.sh is now much the same as the original message subroutines, so just use m4_include to pull that in. This also adds a `(( QUIET )) && return` to the output format section, allowing for a --quiet switch to suppress some output.
Signed-off-by: William Giokas <1007380@gmail.com> ---
Rejected. All amkepkg's messages got to stderr, so it can not use output_format.
Okay. gtmanfred and I were messing with this last night, and without that it messed up the pkgver sed expressions. I'd say that we could have all of the output_format messages to to stderr, but that may not be really advantageous for the other scripts. Personally, I would do that since some of the other scripts call commands (like gpg) that people may want to separate from the scripts output. Guess it's a good thing I split these up into pieces. Thanks, -- William Giokas | KaiSforza GnuPG Key: 0x73CD09CF Fingerprint: F73F 50EF BBE2 9846 8306 E6B8 6902 06D8 73CD 09CF
On Mon, Mar 04, 2013 at 03:11:02AM +1000, Allan McRae wrote:
On 03/03/13 07:50, William Giokas wrote:
output_format.sh is now much the same as the original message subroutines, so just use m4_include to pull that in. This also adds a `(( QUIET )) && return` to the output format section, allowing for a --quiet switch to suppress some output.
Signed-off-by: William Giokas <1007380@gmail.com> ---
Rejected. All amkepkg's messages got to stderr, so it can not use output_format.
Consider that if we're already bent on using m4 for injecting this code into the shell script, it stands to reason that we could quite simply generate this as the output of an m4 function (instead of a direct include) which takes an FD number as a parameter to default the output to.
doc/makepkg.8.txt | 4 ++++ scripts/makepkg.sh.in | 35 +++++++---------------------------- 2 files changed, 11 insertions(+), 28 deletions(-)
diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt index 498c79b..94343b5 100644 --- a/doc/makepkg.8.txt +++ b/doc/makepkg.8.txt @@ -118,6 +118,10 @@ Options Read the package script `buildscript` instead of the `PKGBUILD` default; see linkman:PKGBUILD[5].
+*-q, \--quiet*:: + Suppress makepkg messages. Does not change printing of commands in + PKGBUILD, error or warning messages. + *-r, \--rmdeps*:: Upon successful build, remove any dependencies installed by makepkg during dependency auto-resolution and installation when using `-s`. diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index bd29d73..a90efe5 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -79,6 +79,7 @@ CHECKFUNC=0 PKGFUNC=0 PKGVERFUNC=0 SPLITPKG=0 +QUIET=0 PKGLIST=() SIGNPKG=''
@@ -92,31 +93,7 @@ shopt -s extglob
### SUBROUTINES ###
-plain() { - local mesg=$1; shift - printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -msg() { - local mesg=$1; shift - printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -msg2() { - local mesg=$1; shift - printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -warning() { - local mesg=$1; shift - printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -error() { - local mesg=$1; shift - printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - +m4_include(library/output_format.sh)
## # Special exit call for traps, Don't print any error messages when inside, @@ -2404,6 +2381,7 @@ usage() { printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n" printf -- "$(gettext " -o, --nobuild Download and extract files only")\n" printf -- "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT" + printf -- "$(gettext " -q, --quiet Suppress some makepkg output")\n" printf -- "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")\n" printf -- "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")\n" printf -- "$(gettext " -s, --syncdeps Install missing dependencies with %s")\n" "pacman" @@ -2454,11 +2432,11 @@ fi ARGLIST=("$@")
# Parse Command Line Options. -OPT_SHORT="AcdefFghiLmop:rRsSV" +OPT_SHORT="AcdefFghiLmop:qrRsSV" OPT_LONG=('allsource' 'asroot' 'check' 'clean' 'config:' 'force' 'geninteg' 'help' 'holdver' 'ignorearch' 'install' 'key:' 'log' 'nobuild' 'nocolor' - 'nocheck' 'nodeps' 'noextract' 'nosign' 'pkg:' 'repackage' 'rmdeps' - 'skipchecksums' 'skipinteg' 'skippgpcheck' 'skippgpcheck' 'sign' + 'nocheck' 'nodeps' 'noextract' 'nosign' 'pkg:' 'quiet' 'repackage' + 'rmdeps' 'skipchecksums' 'skipinteg' 'skippgpcheck' 'skippgpcheck' 'sign' 'source' 'syncdeps' 'version')
# Pacman Options @@ -2500,6 +2478,7 @@ while true; do -o|--nobuild) NOBUILD=1 ;; -p) shift; BUILDFILE=$1 ;; --pkg) shift; IFS=, read -ra p <<<"$1"; PKGLIST+=("${p[@]}"); unset p ;; + -q|--quiet) QUIET=1 ;; -r|--rmdeps) RMDEPS=1 ;; -R|--repackage) REPKG=1 ;; --skipchecksums) SKIPCHECKSUMS=1 ;;
On 04/03/13 03:31, Dave Reisner wrote:
On Mon, Mar 04, 2013 at 03:11:02AM +1000, Allan McRae wrote:
On 03/03/13 07:50, William Giokas wrote:
output_format.sh is now much the same as the original message subroutines, so just use m4_include to pull that in. This also adds a `(( QUIET )) && return` to the output format section, allowing for a --quiet switch to suppress some output.
Signed-off-by: William Giokas <1007380@gmail.com> ---
Rejected. All amkepkg's messages got to stderr, so it can not use output_format.
Consider that if we're already bent on using m4 for injecting this code into the shell script, it stands to reason that we could quite simply generate this as the output of an m4 function (instead of a direct include) which takes an FD number as a parameter to default the output to.
Sure - I'd take that without the --quiet part, which needs separate treatment Allan
Use color by default, -m/--no-color turns off colors. Signed-off-by: William Giokas <1007380@gmail.com> --- scripts/pacman-db-upgrade.sh.in | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/pacman-db-upgrade.sh.in b/scripts/pacman-db-upgrade.sh.in index 1b5407a..edd41db 100644 --- a/scripts/pacman-db-upgrade.sh.in +++ b/scripts/pacman-db-upgrade.sh.in @@ -28,11 +28,13 @@ declare -r myver='@PACKAGE_VERSION@' eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf) dbroot="${DBPath:-@localstatedir@/lib/pacman/}" +USE_COLOR='y' + m4_include(library/output_format.sh) usage() { printf "pacman-db-upgrade (pacman) %s\n\n" "$myver" - printf -- "$(gettext "Usage: %s [pacman_db_root]")\n\n" "$0" + printf -- "$(gettext "Usage: %s [-m|--no-color] [pacman_db_root]")\n\n" "$0" } version() { @@ -72,6 +74,13 @@ if [[ $1 = "-V" || $1 = "--version" ]]; then exit 0 fi +if [[ $1 = "-m" || $1 = "--no-color" ]]; then + USE_COLOR='n' + shift +fi + +m4_include(library/term_colors.sh) + if [[ -n $1 ]]; then dbroot="$1" fi -- 1.8.2.rc1.24.g06d67b8
Use --no-color to suppress colored output Signed-off-by: William Giokas <1007380@gmail.com> --- doc/pacman-key.8.txt | 3 +++ scripts/pacman-key.sh.in | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/pacman-key.8.txt b/doc/pacman-key.8.txt index d4a6d5c..f27c873 100644 --- a/doc/pacman-key.8.txt +++ b/doc/pacman-key.8.txt @@ -77,6 +77,9 @@ Operations Locally sign the given key. This is primarily used to root the web of trust in the local private key generated by '\--init'. +*-m, \--no-color*:: + Suppress colored output from pacman-key. + *-r, \--recv-keys*:: Equivalent to '\--recv-keys' in GnuPG. diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index 8f75e2f..93615ec 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -44,6 +44,7 @@ RECEIVE=0 REFRESH=0 UPDATEDB=0 VERIFY=0 +USE_COLOR='y' DEFAULT_KEYSERVER='hkp://pool.sks-keyservers.net' @@ -64,6 +65,7 @@ usage() { printf -- "$(gettext " -e, --export Export the specified or all keyids")\n" printf -- "$(gettext " -f, --finger List fingerprint for specified or all keyids")\n" printf -- "$(gettext " -l, --list-keys List the specified or all keys")\n" + printf -- "$(gettext " -m, --no-color Suppress colored output")\n" printf -- "$(gettext " -r, --recv-keys Fetch the specified keyids")\n" printf -- "$(gettext " -u, --updatedb Update the trustdb of pacman")\n" printf -- "$(gettext " -v, --verify Verify the file(s) specified by the signature(s)")\n" @@ -511,10 +513,10 @@ if ! type gettext &>/dev/null; then } fi -OPT_SHORT="adefhlruvV" +OPT_SHORT="adefhlmruvV" OPT_LONG=('add' 'config:' 'delete' 'edit-key' 'export' 'finger' 'gpgdir:' 'help' 'import' 'import-trustdb' 'init' 'keyserver:' 'list-keys' 'list-sigs' - 'lsign-key' 'populate' 'recv-keys' 'refresh-keys' 'updatedb' + 'lsign-key' 'no-color' 'populate' 'recv-keys' 'refresh-keys' 'updatedb' 'verify' 'version') if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then exit 1 # E_INVALID_OPTION; @@ -543,6 +545,7 @@ while (( $# )); do -l|--list-keys) LISTKEYS=1 ;; --list-sigs) LISTSIGS=1 ;; --lsign-key) LSIGNKEY=1 UPDATEDB=1 ;; + -m|--no-color) USE_COLOR='n' ;; --populate) POPULATE=1 UPDATEDB=1 ;; -r|--recv-keys) RECEIVE=1 UPDATEDB=1 ;; --refresh-keys) REFRESH=1 ;; @@ -557,6 +560,7 @@ while (( $# )); do shift done +m4_include(library/term_colors.sh) if ! type -p gpg >/dev/null; then error "$(gettext "Cannot find the %s binary required for all %s operations.")" "gpg" "pacman-key" -- 1.8.2.rc1.24.g06d67b8
Color enabled by default, turn off with -m or --no-color. Signed-off-by: William Giokas <1007380@gmail.com> --- scripts/pacman-optimize.sh.in | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/pacman-optimize.sh.in b/scripts/pacman-optimize.sh.in index 53ae1c7..262bdf8 100644 --- a/scripts/pacman-optimize.sh.in +++ b/scripts/pacman-optimize.sh.in @@ -24,6 +24,8 @@ export TEXTDOMAIN='pacman-scripts' export TEXTDOMAINDIR='@localedir@' +USE_COLOR='y' + declare -r myver='@PACKAGE_VERSION@' eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf) @@ -33,7 +35,7 @@ m4_include(library/output_format.sh) usage() { printf "pacman-optimize (pacman) %s\n\n" "$myver" - printf -- "$(gettext "Usage: %s [pacman_db_root]")\n\n" "$0" + printf -- "$(gettext "Usage: %s [-m|--no-color] [pacman_db_root]")\n\n" "$0" printf -- "$(gettext "\ pacman-optimize is a little hack that should improve the performance\n\ of pacman when reading/writing to its filesystem-based database.\n\n")" @@ -84,6 +86,13 @@ if [[ $1 = "-V" || $1 = "--version" ]]; then exit 0 fi +if [[ $1 = "-m" || $1 = "--no-color" ]]; then + USE_COLOR='n' + shift +fi + +m4_include(library/term_colors.sh) + if [[ -n $1 ]]; then dbroot="$1" fi -- 1.8.2.rc1.24.g06d67b8
Use color by default. -m and --no-color disable colorized printing. Signed-off-by: William Giokas <1007380@gmail.com> --- scripts/pkgdelta.sh.in | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/pkgdelta.sh.in b/scripts/pkgdelta.sh.in index f9b40c9..36c3383 100644 --- a/scripts/pkgdelta.sh.in +++ b/scripts/pkgdelta.sh.in @@ -29,6 +29,7 @@ export TEXTDOMAINDIR='@localedir@' declare -r myver='@PACKAGE_VERSION@' QUIET=0 +USE_COLOR='y' # minimal of package before deltas are generated (bytes) min_pkg_size=$((1024*1024)) @@ -54,6 +55,7 @@ This delta file can then be added to a database using repo-add.\n\n")" echo printf -- "$(gettext "Options:\n")" printf -- "$(gettext " -q, --quiet minimize output\n")" + printf -- "$(gettext " -m, --no-color remove color from output\n")" printf -- "$(gettext " --min-pkg-size minimum package size before deltas are generated\n")" printf -- "$(gettext " --max-delta-size percent of new package above which the delta will be discarded\n")" } @@ -173,6 +175,8 @@ while :; do exit 0 ;; -q|--quiet) QUIET=1;; + -m|--no-color) + USE_COLOR='n';; --min-pkg-size) if ! min_pkg_size=$(human_to_size "$2"); then echo "invalid argument '$2' for option -- '$1'" @@ -194,6 +198,8 @@ while :; do shift done +m4_include(library/term_colors.sh) + if (( $# != 2 )); then usage exit 1 -- 1.8.2.rc1.24.g06d67b8
Use color by default, use -m or --no-color to suppress colorized output. Signed-off-by: William Giokas <1007380@gmail.com> --- doc/repo-add.8.txt | 3 +++ scripts/repo-add.sh.in | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/doc/repo-add.8.txt b/doc/repo-add.8.txt index 91f3ac6..2bb9acd 100644 --- a/doc/repo-add.8.txt +++ b/doc/repo-add.8.txt @@ -57,6 +57,9 @@ Common Options If the signature is invalid, an error is produced and the update does not proceed. +*-m, \--no-color*:: + Remove color from output of repo-add or repo-remove. + repo-add Options ---------------- *-d, \--delta*:: diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index 3e18a1a..deee0f1 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -37,6 +37,7 @@ VERIFY=0 REPO_DB_FILE= LOCKFILE= CLEAN_LOCK=0 +USE_COLOR='y' # ensure we have a sane umask set umask 0022 @@ -71,6 +72,7 @@ packages to remove can be specified on the command line.\n")" printf -- "$(gettext "Please move along, there is nothing to see here.\n")" return fi + printf -- "$(gettext " -m, --no-color remove color from output\n")" printf -- "$(gettext " -q, --quiet minimize output\n")" printf -- "$(gettext " -s, --sign sign database with GnuPG after update\n")" printf -- "$(gettext " -k, --key <key> use the specified key to sign the database\n")" @@ -610,6 +612,7 @@ while (( $# )); do -d|--delta) DELTA=1;; -n|--new) ONLYADDNEW=1;; -f|--files) WITHFILES=1;; + -m|--no-color) USE_COLOR='n';; -s|--sign) check_gpg SIGN=1 @@ -642,6 +645,8 @@ while (( $# )); do shift done +m4_include(library/term_colors.sh) + REPO_DB_FILE=${args[0]} if [[ -z $REPO_DB_FILE ]]; then usage -- 1.8.2.rc1.24.g06d67b8
participants (3)
-
Allan McRae
-
Dave Reisner
-
William Giokas