diff options
-rw-r--r-- | functions | 41 |
1 files changed, 32 insertions, 9 deletions
@@ -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: |