[arch-general] [PATCH 02/48] Tighten up the console size finding code a bit.

Victor Lowther victor.lowther at gmail.com
Wed Jun 30 17:47:41 EDT 2010


---
 functions |   30 +++++++++++++-----------------
 1 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/functions b/functions
index 023de35..a9acf6f 100644
--- a/functions
+++ b/functions
@@ -5,26 +5,21 @@
 # width:
 
 STAT_COL=80
-if [ ! -t 1 ]; then
-  USECOLOR=""
-
-# stty will fail when stdin isn't a terminal
-elif [ -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
+if [[ ! -t 1 ]]; then
+    USECOLOR=""
+elif [[ -t 0 ]]; then
+    # stty will fail when stdin isn't a terminal
+    STAT_COL="$(/bin/stty size)"
+    # stty gives "rows cols"; strip the rows number, we just want columns
+    STAT_COL="${STAT_COL##* }"
+elif /bin/tput cols &>/dev/null; then
   # is /usr/share/terminfo already mounted, and TERM recognized?
-  /bin/tput cols &>/dev/null
-  if [ $? -eq 0 ]; then
     STAT_COL=$(/bin/tput cols)
-  fi
 fi
-if [ "0$STAT_COL" -eq 0 ]; then
-  # if output was 0 (serial console), set default width to 80
-  STAT_COL=80
-  USECOLOR=""
+if ((STAT_COL==0)); then
+    # if output was 0 (serial console), set default width to 80
+    STAT_COL=80
+    USECOLOR=""
 fi
 
 # we use 13 characters for our own stuff
@@ -54,6 +49,7 @@ unset TZ
 # colors:
 if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then
 	C_MAIN="\033[1;37;40m"      # main text
+
 	C_OTHER="\033[1;34;40m"     # prefix & brackets
 	C_SEPARATOR="\033[1;30;40m" # separator
 
-- 
1.7.1



More information about the arch-general mailing list