From d9f823e06902b93c9a708bf831128fe0f4d8d5a3 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Thu, 9 Jan 2014 11:27:57 +0000 Subject: [PATCH] add is_true function and stub upport for color is_true will return true for various sorts of "true" values of its argument, specifically '1', 't', 'true', 'yes, and 'y'. Anything else is false. --- scripts/functions.rc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/functions.rc b/scripts/functions.rc index fb2b6d9..854a567 100644 --- a/scripts/functions.rc +++ b/scripts/functions.rc @@ -1,3 +1,15 @@ +#!/bin/sh + +if [ "$USE_COLOR" = '1' ] && [ -x /usr/bin/tput ]; then +red=$(tput setaf 1) +green=$(tput setaf 2) +off=$(tput sgr0) +fi + +status_msg() { + echo "\r[$1]" +} + status_starting() { echo -n "[ ] Starting $1" } @@ -11,7 +23,7 @@ status_stopping() { } status_ok() { - echo "\r[ OK ]" + echo "\r[ ${green}OK$off ]" } status_fail() { @@ -21,3 +33,8 @@ status_fail() { status_check() { test $? -eq 0 && status_ok || status_fail } + +is_true() { + [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] || [ "$1" = "y" ] || + [ "$1" = "t" ] +} -- 2.40.0