]> pd.if.org Git - startuptools/commitdiff
add is_true function and stub upport for color
authorNathan Wagner <nw@hydaspes.if.org>
Thu, 9 Jan 2014 11:27:57 +0000 (11:27 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Thu, 9 Jan 2014 11:27:57 +0000 (11:27 +0000)
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

index fb2b6d9353f261cd20e08ec70628679563384390..854a56735c3e1af787a09b41f95eeaf6ee2db962 100644 (file)
@@ -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"
 }
 status_starting() {
        echo -n "[      ] Starting $1"
 }
@@ -11,7 +23,7 @@ status_stopping() {
 }
 
 status_ok() {
 }
 
 status_ok() {
-       echo    "\r[  OK  ]"
+       echo    "\r[  ${green}OK$off  ]"
 }
 
 status_fail() {
 }
 
 status_fail() {
@@ -21,3 +33,8 @@ status_fail() {
 status_check() {
        test $? -eq 0 && status_ok || status_fail
 }
 status_check() {
        test $? -eq 0 && status_ok || status_fail
 }
+
+is_true() {
+   [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] ||  [ "$1" = "y" ] ||
+   [ "$1" = "t" ]
+}