File: dumpbeautify.sh

package info (click to toggle)
herbstluftwm 0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 684 kB
  • sloc: ansic: 6,168; sh: 399; makefile: 117
file content (63 lines) | stat: -rwxr-xr-x 1,120 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash

# aligns the output of dump command as a nice tree
# usage:
# herbstclient dump | ./dumpbeatify.sh

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";
}

$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'