From 952e2465b332afea6265fa9845230179a45bdff0 Mon Sep 17 00:00:00 2001 From: William Melody Date: Sun, 7 Jun 2020 13:17:24 -0700 Subject: [PATCH] Add `_warn()` and use in `completions`. --- hosts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/hosts b/hosts index c0a3a25..cb81d28 100755 --- a/hosts +++ b/hosts @@ -154,6 +154,22 @@ _return_1() { return 1 } +# _warn() +# +# Usage: +# _warn +# +# Description: +# Print the specified command with output redirected to standard error. +# The command is expected to print a message and should typically be either +# `echo`, `printf`, or `cat`. +_warn() { + { + printf "%s " "$(tput setaf 1)!$(tput sgr0)" + "${@}" + } 1>&2 +} + ############################################################################### # Load Commands ############################################################################### @@ -1106,10 +1122,10 @@ HEREDOC printf "Completion script installed: %s\\n" \ "${_completion_target}" else - printf "Exists: %s\\n" "${_completion_target}" + _warn printf "Exists: %s\\n" "${_completion_target}" fi else - printf "Permission denied: %s\\n" "${_completion_path}" + _warn printf "Permission denied: %s\\n" "${_completion_path}" fi fi fi @@ -1146,7 +1162,7 @@ HEREDOC "${_completion_target}" fi else - printf "Permission denied: %s\\n" "${_completion_path}" + _warn printf "Permission denied: %s\\n" "${_completion_path}" fi fi done