aboutsummaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
authorJim Pryor <jim.pryor@nyu.edu>2009-08-05 10:09:27 -0700
committerAaron Griffin <aaronmgriffin@gmail.com>2009-08-05 10:09:27 -0700
commit0e36fec20e3c27eaa459e1083833cb85ccf2b34b (patch)
treec98fea6fae73dfabb2b29045484b4a9af0cf0186 /functions
parent9b43beb2965812a811dd266a30b2b50f589fd455 (diff)
downloadinitscripts-0e36fec20e3c27eaa459e1083833cb85ccf2b34b.tar.xz
Fix stty/tput usage for columns
This corrects the usage of stty and tput under various non-TTY conditions such as under cron and redirected output. [Aaron: Also corrected my USECOLOR bug I introduced last patch] Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
Diffstat (limited to 'functions')
-rw-r--r--functions41
1 files changed, 32 insertions, 9 deletions
diff --git a/functions b/functions
index 96903b9..0f333d4 100644
--- a/functions
+++ b/functions
@@ -4,9 +4,28 @@
# width:
-# disable color on output to non-tty
STAT_COL=80
-USECOLOR=""
+if [ -t 1 ]; then
+ # stty will fail when stdin isn't a terminal (but we're in this block, so stdout is)
+ if [ -t 0 ]; then
+ STAT_COL="$(/bin/stty size)"
+ # stty gives "rows cols"; strip the rows number, we just want columns
+ STAT_COL="${STAT_COL##* }"
+ else
+ # tput will fail at boot time if /usr/share/terminfo isn't yet mounted
+ # or TERM is otherwise unrecognized
+ STAT_COL="$(/bin/tput cols 2>/dev/null)"
+ fi
+ if [ "0$STAT_COL" -eq 0 ]; then
+ # if output was 0 (serial console), set default width to 80
+ USECOLOR=""
+ STAT_COL=80
+ fi
+else
+ USECOLOR=""
+ STAT_COL=80
+fi
+
if [ -t 1 ]; then
STAT_COL=$(/bin/stty size)
# strip the rows number, we just want columns
@@ -140,13 +159,17 @@ status() {
# 1 - not found
# Copied from makepkg
in_array() {
- local needle=$1; shift
- [ -z "$1" ] && return 1 # Not Found
- local item
- for item in "$@"; do
- [ "$item" = "$needle" ] && return 0 # Found
- done
- return 1 # Not Found
+ local needle=$1; shift
+ [ -z "$1" ] && return 1 # Not Found
+ local item
+ for item in "$@"; do
+ local c="${item:0:1}"
+ if [ "$c" == "!" -o "$c" == "@" ]; then
+ item="${item:1}"
+ fi
+ [ "$item" = "$needle" ] && return 0 # Found
+ done
+ return 1 # Not Found
}
# daemons: