lib/utils: Refactor

This commit is contained in:
Koichi Murase
2021-12-28 07:50:11 +09:00
parent d59c91bc35
commit d6100b81fc

View File

@ -102,16 +102,16 @@ function _omb_util_defun_deprecate {
if which tput >/dev/null 2>&1; then if which tput >/dev/null 2>&1; then
ncolors=$(tput colors) ncolors=$(tput colors)
fi fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then if [[ -t 1 && $ncolors && ncolors -ge 8 ]]; then
bold="$(tput bold)" bold=$(tput bold 2>/dev/null)
underline=$(tput sgr 0 1) underline=$(tput sgr 0 1 2>/dev/null)
reset="$(tput sgr0)" reset=$(tput sgr0 2>/dev/null)
red="$(tput setaf 1)" red=$(tput setaf 1 2>/dev/null)
green="$(tput setaf 2)" green=$(tput setaf 2 2>/dev/null)
yellow="$(tput setaf 3)" yellow=$(tput setaf 3 2>/dev/null)
blue="$(tput setaf 4)" blue=$(tput setaf 4 2>/dev/null)
purple=$(tput setaf 171) purple=$(tput setaf 171 2>/dev/null)
tan=$(tput setaf 3) tan=$(tput setaf 3 2>/dev/null)
else else
bold="" bold=""
underline="" underline=""
@ -163,10 +163,7 @@ seek_confirmation() {
# Test whether the result of an 'ask' is a confirmation # Test whether the result of an 'ask' is a confirmation
is_confirmed() { is_confirmed() {
if [[ "$REPLY" =~ ^[Yy]$ ]]; then [[ $REPLY =~ ^[Yy]$ ]]
return 0
fi
return 1
} }
# #
@ -217,10 +214,7 @@ _omb_util_defun_deprecate 20000 type_exists _omb_util_binary_exists
# Usage: if is_os 'darwin'; then # Usage: if is_os 'darwin'; then
# #
is_os() { is_os() {
if [[ "${OSTYPE}" == $1* ]]; then [[ $OSTYPE == $1* ]]
return 0
fi
return 1
} }
# #