All posts by ticapix

Pretty Check

Demo
prettycheck

Code

#!/bin/sh

function prettycheck {
    local TPUT='tput'
    local RED='1'
    local GREEN='2'
    local BLUE='4'
#man 5 terminfo

    [ ! -f $(which $TPUT) ] && TPUT=true

    cmd="$@"
    echo "$> $cmd"
    $TPUT cuf $((`$TPUT cols` - 8)) # move the end-of-line minus 8 cols
    $TPUT cuu 1 # move on line up
    msgerr=$($cmd 2>&1 1> /dev/null)
    if [ "$?" -ne 0 ]; then
        $TPUT setaf $RED # change front color
        echo "[FAILED]"
        $TPUT setaf $BLUE # change front color
        echo "$msgerr"
    else
        $TPUT setaf $GREEN # change front color
        echo "[  OK  ]"                                                                                   
    fi                                                                                                    
    $TPUT reset                                                                                           
}