]> piware.de Git - bin.git/commitdiff
shellpresent: add variables for colors, support dark background
authormartin@piware.de <>
Mon, 6 Apr 2009 21:35:49 +0000 (14:35 -0700)
committermartin@piware.de <>
Mon, 6 Apr 2009 21:35:49 +0000 (14:35 -0700)
shellpresent

index a9720d6556b50480aaea377448a4ea1e42755571..b0758f79f7ec1922d6ed9d0c12f3a41eb65533dd 100755 (executable)
@@ -7,27 +7,51 @@
 # (c) 2009 Martin Pitt <martin@piware.de>
 # License: Public Domain
 
+NORMAL=""
+BOLD=";1"
+STATE=$NORMAL
+
+OFF=0
+RED=31$STATE
+GREEN=32$STATE
+YELLOW=33$STATE
+BLUE=34$STATE
+MAGENTA=35$STATE
+CYAN=36$STATE
+
+# Presentation colors
+COMMENT=$GREEN
+PROMPT=$RED
+CMD=$BLUE
+OUTPUT=$OFF
+
+if [ "x$1" = 'x--dark' ]; then
+    shift || true
+    STATE=$BOLD
+    CMD=$YELLOW
+fi
+
 [ -e "$1" ] || {
-    echo "Usage: $0 <shell script>" >&2
+    echo "Usage: $0 [--dark] <shell script>" >&2
     exit 1
 }
 
 clear
-echo -en "\e[31m\$\e[30m "
+echo -en "\e[${PROMPT}m\$\e[${CMD}m "
 
 while read line; do
     # paragraph clears screen
     if [ -z "$line" ]; then
        clear
-       echo -en "\e[31m\$\e[30m "
+       echo -en "\e[${PROMPT}m\$\e[${CMD}m "
        continue
     fi
 
     # comment
     if [ "${line:0:1}" = "#" ]; then
        if [ -n "${line:1}" ]; then
-           echo -e "\r\e[32m$line\e[30m"
-           echo -en "\e[31m\$\e[30m "
+           echo -e "\r\e[${COMMENT}m$line\e[${CMD}m"
+           echo -en "\e[${PROMPT}m\$\e[${CMD}m "
        fi
        continue
     fi
@@ -35,7 +59,8 @@ while read line; do
     # execute command
     echo -n "$line"
     read < /dev/tty
+    echo -ne "\e[${OUTPUT}m"
     eval "$line"
-    echo -en "\n\e[31m\$\e[30m "
+    echo -en "\n\e[${PROMPT}m\$\e[${CMD}m "
     read -s < /dev/tty
 done < "$1"