From b05933da4de82fe515c1eee5e5a7690072b99c79 Mon Sep 17 00:00:00 2001 From: Aaron Griffin Date: Thu, 30 Jul 2009 20:15:31 -0700 Subject: functions: refactor for non-tty output This commit should allow rc.d scripts to be run from non-tty's, such as a cron job Signed-off-by: Aaron Griffin --- functions | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'functions') diff --git a/functions b/functions index f84fb5e..96903b9 100644 --- a/functions +++ b/functions @@ -4,16 +4,17 @@ # width: -STAT_COL=$(/bin/stty size) -# strip the rows number, we just want columns -STAT_COL=${STAT_COL##* } -if [ "$STAT_COL" = "0" ]; then - # if output was 0 (serial console), set default width to 80 - STAT_COL=80 -elif [ ! -t 1 ]; then - # disable color on output to non-tty - STAT_COL=80 - USECOLOR="" +# disable color on output to non-tty +STAT_COL=80 +USECOLOR="" +if [ -t 1 ]; then + STAT_COL=$(/bin/stty size) + # strip the rows number, we just want columns + STAT_COL=${STAT_COL##* } + if [ "$STAT_COL" = "0" ]; then + # if output was 0 (serial console), set default width to 80 + STAT_COL=80 + fi fi # we use 13 characters for our own stuff STAT_COL=$(($STAT_COL - 13)) @@ -60,6 +61,10 @@ if [ -t 1 ]; then SAVE_POSITION="\033[s" RESTORE_POSITION="\033[u" DEL_TEXT="\033[$(($STAT_COL+4))G" +else + SAVE_POSITION="" + RESTORE_POSITION="" + DEL_TEXT="" fi # prefixes: -- cgit v1.2.3