diff options
author | William Giokas <1007380@gmail.com> | 2013-03-04 02:42:34 -0600 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2013-03-08 17:04:40 +1000 |
commit | f8ed8620d03e7e6fc58815bbee5b65c786fbc423 (patch) | |
tree | ab1b343dcf9d011217d915686064b46aafa0fd51 | |
parent | 5a67eee78c58475907a2128c46c08c137d41e4f9 (diff) |
contrib: Make pacdiff colors the same as makepkg
Added an `ask` message function that emulates pacman's appearance.
Signed-off-by: William Giokas <1007380@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r-- | contrib/pacdiff.sh.in | 35 | ||||
-rw-r--r-- | scripts/library/output_format.sh | 5 |
2 files changed, 14 insertions, 26 deletions
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in index b41544fc..47779d6b 100644 --- a/contrib/pacdiff.sh.in +++ b/contrib/pacdiff.sh.in @@ -24,22 +24,11 @@ declare -r myver='@PACKAGE_VERSION@' diffprog=${DIFFPROG:-vimdiff} diffsearchpath=${DIFFSEARCHPATH:-/etc} locate=0 +USE_COLOR='y' -if tput setaf 0 &>/dev/null; then - ALL_OFF="$(tput sgr0)" - BOLD="$(tput bold)" - BLUE="${BOLD}$(tput setaf 4)" - GREEN="${BOLD}$(tput setaf 2)" - YELLOW="${BOLD}$(tput setaf 3)" - PURPLE="${BOLD}$(tput setaf 5)" -else - ALL_OFF="\e[1;0m" - BOLD="\e[1;1m" - BLUE="${BOLD}\e[1;34m" - GREEN="${BOLD}\e[1;32m" - YELLOW="${BOLD}\e[1;33m" - PURPLE="${BOLD}\e[1;35m" -fi +m4_include(../scripts/library/output_format.sh) + +m4_include(../scripts/library/term_colors.sh) usage() { echo "$myname : a simple pacnew/pacorig/pacsave updater" @@ -82,24 +71,18 @@ while IFS= read -u 3 -r -d '' pacfile; do file="${pacfile%.pac*}" file_type="pac${pacfile##*.pac}" - case $file_type in - pacnew) printf "$GREEN%s$ALL_OFF" "$file_type";; - pacorig) printf "$YELLOW%s$ALL_OFF" "$file_type";; - pacsave) printf "$BLUE%s$ALL_OFF" "$file_type";; - esac - - printf " file found for $PURPLE%s$ALL_OFF\n" "$file" + msg "%s file found for %s" "$file_type" "$file" if [ ! -f "$file" ]; then - echo " $file does not exist" + warning "$file does not exist" rm -iv "$pacfile" continue fi if cmp -s "$pacfile" "$file"; then - echo " Files are identical, removing..." + msg2 "Files are identical, removing..." rm -v "$pacfile" else - printf " (V)iew, (S)kip, (R)emove %s, (O)verwrite with %s: [v/s/r/o] " "$file_type" "$file_type" + ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s: [v/s/r/o] " "$file_type" "$file_type" while read c; do case $c in r|R) rm -v "$pacfile"; break ;; @@ -108,7 +91,7 @@ while IFS= read -u 3 -r -d '' pacfile; do $diffprog "$pacfile" "$file" rm -iv "$pacfile"; break ;; s|S) break ;; - *) printf " Invalid answer. Try again: [v/s/r/o] "; continue ;; + *) ask "Invalid answer. Try again: [v/s/r/o] "; continue ;; esac done fi diff --git a/scripts/library/output_format.sh b/scripts/library/output_format.sh index 18f1f588..9f02c00b 100644 --- a/scripts/library/output_format.sh +++ b/scripts/library/output_format.sh @@ -16,6 +16,11 @@ msg2() { printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1 } +ask() { + local mesg=$1; shift + printf "${BLUE}::${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}" "$@" >&1 +} + warning() { local mesg=$1; shift printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 |