emerge-status.sh: cleanup Bash command substitution and testing
authorW. Trevor King <wking@tremily.us>
Thu, 6 Dec 2012 17:46:20 +0000 (12:46 -0500)
committerW. Trevor King <wking@tremily.us>
Thu, 6 Dec 2012 17:48:59 +0000 (12:48 -0500)
posts/conky/emerge-status.sh

index a1241efde5d7140693d3f85ecbbc0f4a0dcaa0d1..b951e2f3de6034ee051344a67533903f5e1ba10d 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 #
-# emerge-status.sh by Hellf[i]re
+# emerge-status.sh (originally by Hellf[i]re)
 #
 # This script will report the current status of portage.
 #
 #  would be far too much parsing required to find out the current status of
 #  every command which is run in parallel.
 
-STATUS=`tail -n 15 /var/log/emerge.log |\
-grep -iE "Compiling|Cleaning|AUTOCLEAN|completed|search|terminating|rsync" |\
-cut -d ' ' -f "2-" |\
-grep -Ev 'Finished\.|Cleaning up\.\.\.' |\
-tail -n 1`
+STATUS=$(
+       tail -n 15 /var/log/emerge.log |
+       grep -iE "Compiling|Cleaning|AUTOCLEAN|completed|search|terminating|rsync" |
+       cut -d ' ' -f "2-" |
+       grep -Ev 'Finished\.|Cleaning up\.\.\.' |
+       tail -n 1)
 
-#echo "$STATUS"
-
-if [ "`echo "$STATUS" | grep -i compiling`" != "" ]; then echo Compiling
-elif [ "`echo "$STATUS" | grep -i cleaning`" != "" ]; then echo Cleaning
-elif [ "`echo "$STATUS" | grep -i autoclean`" != "" ]; then echo Autoclean
-elif [ "`echo "$STATUS" | grep -i sync`" != "" ]; then echo Syncing
-elif [ "`echo "$STATUS" | grep -i search`" != "" ]; then echo Searching
-elif [ "`echo "$STATUS" | grep -i completed`" != "" ]; then echo Completed
-elif [ "`echo "$STATUS" | grep -i terminating`" != "" ]; then echo Completed
+if [ -n "$(echo "$STATUS" | grep -i compiling)" ]; then echo Compiling
+elif [ -n "$(echo "$STATUS" | grep -i cleaning)" ]; then echo Cleaning
+elif [ -n "$(echo "$STATUS" | grep -i autoclean)" ]; then echo Autoclean
+elif [ -n "$(echo "$STATUS" | grep -i sync)" ]; then echo Syncing
+elif [ -n "$(echo "$STATUS" | grep -i search)" ]; then echo Searching
+elif [ -n "$(echo "$STATUS" | grep -i completed)" ]; then echo Completed
+elif [ -n "$(echo "$STATUS" | grep -i terminating)" ]; then echo Completed
 else echo Script Error!
 fi