#!/bin/bash # Beautify my 'aptitude update && aptitude -s -y safe-upgrade' output # Optimized for aptitude 0.6.3 RED='\e[0;31m' GREEN='\e[0;32m' YELLOW='\e[0;33m' RESET='\e[0m' cecho() { if [ -t 1 ]; then # Only use colors when file descriptor FD is open and refers to a terminal. echo -n -e "$2$1" else if [ "$2" == $RESET ] ; then echo -n -e "$1" else echo -n "$1" fi fi } printf "%-38s" "Updating package list..." if (aptitude update > /dev/null 2>&1); then echo -n "[ " cecho "Done" $GREEN cecho " ]\n" $RESET else echo -n "[ " cecho "FAILED" $RED cecho " ]\n" $RESET exit 1 fi x=0 aptitude -q -s -y safe-upgrade 2>&1 | while read LINE; do if [ ! "$LINE" == "" ]; then if [[ $x -gt 5 ]]; then if [[ "$LINE" =~ '0 packages upgraded' ]]; then cecho "" $RESET else [[ "$LINE" =~ 'packages upgraded,' ]] && cecho "\n" $RESET fi echo "$LINE" [ $x -eq 6 ] && let x++ && cecho "" $YELLOW && echo else LINE=$(echo $LINE | tr -d '\n') let x++ printf "%-38s" "$LINE" echo -n "[ " cecho "Done" $GREEN cecho " ]\n" $RESET [ $x -eq 6 ] && echo fi fi done echo