summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorThorsten Wißmann <edu@thorsten-wissmann.de>2011-09-23 16:02:39 +0200
committerThorsten Wißmann <edu@thorsten-wissmann.de>2011-09-23 16:02:39 +0200
commit1b06cc8ca802c077b36368148eb845b79d90ca54 (patch)
tree7aa7e09ac7d841c9e1172246640ccc1fe496c29e /scripts
parent9e6cbe4800b37f1cc82330fa05c8329b1c703e1a (diff)
migrated dumpbeatify.sh to awk with colors
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/dumpbeatify.sh68
1 files changed, 54 insertions, 14 deletions
diff --git a/scripts/dumpbeatify.sh b/scripts/dumpbeatify.sh
index c4fd47ef..29a01751 100755
--- a/scripts/dumpbeatify.sh
+++ b/scripts/dumpbeatify.sh
@@ -4,20 +4,60 @@
# usage:
# herbstclient dump | ./dumpbeatify.sh
-indent=""
-
-# an ugly hack, but it's okey:
-IFS="" # we do not need fields
-# but with IFS="" read -n 1 can read spaces :)
-
-function p(){
- while read -n 1 p ; do
- [ "$p" = '(' ] && echo -en '\n'"$indent"'(' && indent+=' ' && ( p ) && continue
- [ "$p" = ')' ] && echo -en ')' && return 0
- echo -n "$p"
- done
- echo
+awkcode='
+BEGIN {
+ indent=2
+ ORS="";
+ x=0;
+ open=0;
+ first=1
+ i=0;
+ color[i++]="\033[1;31m";
+ color[i++]="\033[1;32m";
+ color[i++]="\033[1;33m";
+ color[i++]="\033[1;34m";
+ color[i++]="\033[1;35m";
+ color[i++]="\033[1;36m";
+ color[i++]="\033[1;37m";
+ color[i++]="\033[0;31m";
+ color[i++]="\033[0;32m";
+ color[i++]="\033[0;33m";
+ color[i++]="\033[0;34m";
+ color[i++]="\033[0;35m";
+ color[i++]="\033[0;36m";
+ color[i++]="\033[0;37m";
}
-p | sed '/^[ ]*$/d'
+$1 ~ "^[(]" {
+ if (first == 0) {
+ printf "\n";
+ printf "%"(indent*x)"s" , "" ;
+ } else {
+ first=0;
+ }
+ color_bracket[x]=open
+ print color[(color_bracket[x]) % length(color)]
+ print ;
+ x++
+ open++;
+}
+
+$1 ~ "[)]" {
+ x-- ;
+ print color[(color_bracket[x]) % length(color)]
+ print
+}
+
+END {
+ printf "\n"
+}
+'
+
+clear=$(tput sgr0) || clear=$(echo -e '\e[0m')
+
+sed 's/\([()]\)/\n\1/g' | # insert newlines before (
+ awk "$awkcode" |
+ sed 's#(#('"$clear"'#g'
+
+