summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Ismael Haase Hernández <hahj87@gmail.com>2011-12-24 21:23:11 -0600
committerJoshua Ismael Haase Hernández <hahj87@gmail.com>2011-12-24 21:23:11 -0600
commitcc746eb378b3d24a38e6f6b58890061fd2a995dd (patch)
tree60d83ca68adf28fd2f24b11968bb6fa04ab98f29
parent55b66d324fb5b08651606207bec73f4d51525c7e (diff)
libremessages: added in_array function
-rwxr-xr-xlibremessages59
1 files changed, 42 insertions, 17 deletions
diff --git a/libremessages b/libremessages
index d333f3f..5d817dd 100755
--- a/libremessages
+++ b/libremessages
@@ -26,24 +26,27 @@ export TEXTDOMAINDIR='/usr/share/locale'
# check if messages are to be printed using color
unset ALL_OFF BOLD BLUE GREEN RED YELLOW
-
-if tput setaf 0 &>/dev/null; then
- ALL_OFF="$(tput sgr0)"
- BOLD="$(tput bold)"
- BLUE="${BOLD}$(tput setaf 4)"
- GREEN="${BOLD}$(tput setaf 2)"
- RED="${BOLD}$(tput setaf 1)"
- YELLOW="${BOLD}$(tput setaf 3)"
- PURPLE="${ALL_OFF}$(tput setaf 5)"
-else
- ALL_OFF="\033[1;0m"
- BOLD="\033[1;1m"
- BLUE="${BOLD}\033[1;34m"
- GREEN="${BOLD}\033[1;32m"
- RED="${BOLD}\033[1;31m"
- YELLOW="${BOLD}\033[1;33m"
- PURPLE="${BOLD}\033[1;30;40m"
+if [[ -t 2 ]]; then
+ # prefer terminal safe colored and bold text when tput is supported
+ if tput setaf 0 &>/dev/null; then
+ ALL_OFF="$(tput sgr0)"
+ BOLD="$(tput bold)"
+ PURPLE="${ALL_OFF}$(tput setaf 5)"
+ BLUE="${BOLD}$(tput setaf 4)"
+ GREEN="${BOLD}$(tput setaf 2)"
+ RED="${BOLD}$(tput setaf 1)"
+ YELLOW="${BOLD}$(tput setaf 3)"
+ else
+ ALL_OFF="\e[1;0m"
+ BOLD="\e[1;1m"
+ BLUE="${BOLD}\e[1;34m"
+ GREEN="${BOLD}\e[1;32m"
+ RED="${BOLD}\e[1;31m"
+ YELLOW="${BOLD}\e[1;33m"
+ PURPLE="${BOLD}\033[1;30;40m"
+ fi
fi
+readonly ALL_OFF BOLD BLUE GREEN RED YELLOW PURPLE
stdnull() {
eval "$@ >/dev/null 2>&1"
@@ -74,3 +77,25 @@ error() {
printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
+stat_busy() {
+ local mesg=$1; shift
+ printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" >&2
+}
+
+stat_done() {
+ printf "${BOLD}done${ALL_OFF}\n" >&2
+}
+
+# usage : in_array( $needle, $haystack )
+in_array() {
+ [[ $2 ]] || return 1 # Not found
+
+ local needle=$1; shift
+ local item
+
+ for item in "$@"; do
+ [[ ${item#@} = $needle ]] && return 0 # Found
+ done
+
+ return 1 # Not Found
+}