Просмотр исходного кода

Make several imprrovements to i3staplus

Alois Mahdal 10 месяцев назад
Родитель
Сommit
d8af7c8076
1 измененных файлов: 134 добавлений и 5 удалений
  1. 134
    5
      dotfiles/config/i3/bin/i3staplus

+ 134
- 5
dotfiles/config/i3/bin/i3staplus Просмотреть файл

2
 
2
 
3
 # prepend i3status with more stuff
3
 # prepend i3status with more stuff
4
 
4
 
5
+
6
+I3STAPLUS__SSHAK_NEED=${I3STAPLUS__SSHAK_NEED:-F}
7
+I3STAPLUS__LOG=${I3STAPLUS__LOG:-true}
8
+I3STAPLUS__LOGDIR=${I3STAPLUS__LOGDIR:-"$HOME/.local/share/i3staplus/logs"}
9
+I3STAPLUS__KPRINC_NEED=${I3STAPLUS__KPRINC_NEED:-T}
10
+
5
 kb_layout() {
11
 kb_layout() {
6
     local layout
12
     local layout
7
     local color
13
     local color
24
     test -s "$ovw_path" || return 0
30
     test -s "$ovw_path" || return 0
25
     ovw=$(cat "$ovw_path")
31
     ovw=$(cat "$ovw_path")
26
     case $ovw in
32
     case $ovw in
27
-        *%onbreak)  color=',"color": "#33aa55"' ;;
33
+        *%gone)     color=',"color": "#ff0000"' ;;
28
         *%mtg)      color=',"color": "#ff0000"' ;;
34
         *%mtg)      color=',"color": "#ff0000"' ;;
35
+        *%onbreak)  color=',"color": "#33aa55"' ;;
29
         *%working)  color=',"color": "#cccccc"' ;;
36
         *%working)  color=',"color": "#cccccc"' ;;
30
         *)          color='' ;;
37
         *)          color='' ;;
31
     esac
38
     esac
33
         "$ovw" "$color"
40
         "$ovw" "$color"
34
 }
41
 }
35
 
42
 
43
+morf_V() {
44
+    return 0
45
+    local ver
46
+    local err=F
47
+    local color
48
+    ver=$(morf -V) || err=T
49
+    test -n "$ver" || ver="(none)"
50
+    case $err:$ver in
51
+        T:*)    color=',"color": "#ff0000"' ;;
52
+        *:*+*)  color=',"color": "#f08000"' ;;
53
+    esac
54
+    printf '{"full_text": "ⓜ %s"%s},' \
55
+        "$ver" "$color"
56
+}
57
+
58
+gibrs() {
59
+    local out
60
+    out=$(showgbr)
61
+    test -n "$out" || return 0
62
+    printf '{"full_text": "ⓖ %s"},' \
63
+       "$out"
64
+}
65
+
66
+kprinc() {
67
+    local principal
68
+    local err=F
69
+    local color=',"color": "%cccccc"'
70
+    principal=$(
71
+        klist -A 2>/dev/null \
72
+          | grep -m1 '^Default principal: ' \
73
+          | cut -d' ' -f3- \
74
+          | tr '@' '\n' \
75
+          | tr '.' '\n' \
76
+          | grep -o '^.' \
77
+          | tr -d '\n'
78
+    )
79
+    principal_n=$(
80
+        klist -A 2>/dev/null \
81
+          | grep -c '^Default principal: '
82
+    )
83
+    case "$principal_n" in
84
+        0)  principal='(n)'
85
+            color=',"color": "#f08000"' ;;
86
+        1)  : ;;
87
+        *)  principal="$principal+" ;;
88
+    esac
89
+    printf '{"full_text": "ⓚ %s"%s},' \
90
+        "$principal" "$color"
91
+}
92
+
93
+sshak() {
94
+    local keys_desc
95
+    local keys_n
96
+    local err=F
97
+    local color=',"color": "#cccccc"'
98
+    keys_n=$(
99
+        ssh-add -l \
100
+          | grep -cv 'The agent has no identities'
101
+    )
102
+    keys_desc=$(
103
+        ssh-add -l \
104
+          | grep -v 'The agent has no identities' \
105
+          | while read -r k_size k_id k_cmt k_alg; do
106
+                shortcmt=$(
107
+                    echo "$k_cmt" \
108
+                      | sed -E '
109
+                            s/([^@]).*@([^ ]).*/\1@\2/
110
+                        '
111
+                )
112
+                test -n "$shortcmt" \
113
+                 && echo "$shortcmt" \
114
+                 && continue
115
+                echo "$k_id" | sed -E 's/.*:(...).*/\1/'
116
+            done
117
+    )
118
+    case "$keys_n:$I3STAPLUS__SSHAK_NEED" in
119
+        0:T)    color=',"color": "#f08000"'; keys_desc='(n)' ;;
120
+        0:*)                                 keys_desc='(n)' ;;
121
+#       *)      color=',"color": "#cccccc"' ;;
122
+    esac
123
+    printf '{"full_text": "ⓢ %s"%s},' \
124
+        "$keys_desc" "$color"
125
+}
126
+
127
+m_sprintn() {
128
+    return 0
129
+    local sprintn
130
+    local color
131
+    local ccode
132
+    sprintn=$(scrumq)
133
+    case $sprintn in
134
+        *r3) ccode='#ffddcc' ;; # Mon
135
+        *r2) ccode='#ffaa99' ;;
136
+        *r1) ccode='#ff7766' ;;
137
+        *r0) ccode='#ff3333' ;;
138
+        *)  ccode='' ;;
139
+    esac
140
+    test -n "$ccode" && color=',"color": "'"$ccode"'"'
141
+    printf '{"full_text": " %s"%s},' \
142
+        "$sprintn" "$color"
143
+}
144
+
145
+if test "x$I3STAPLUS__LOG" = "xtrue"; then
146
+    mkdir -p "$I3STAPLUS__LOGDIR"
147
+    log_pre() {
148
+        tee "$I3STAPLUS__LOGDIR/debug-pre.json"
149
+    }
150
+    log_post() {
151
+        tee "$I3STAPLUS__LOGDIR/debug-post.json"
152
+    }
153
+else
154
+    log_pre() {
155
+        cat
156
+    }
157
+    log_post() {
158
+        cat
159
+    }
160
+fi
161
+
36
 i3status \
162
 i3status \
163
+  | log_pre \
37
   | while true
164
   | while true
38
     do
165
     do
39
-        read line
166
+        read -r line
167
+        INFIX="$(kb_layout)$(bmo_be_ovw)$(gibrs)$(kprinc)$(sshak)"
40
         case $line in
168
         case $line in
41
-            '[{'*)  line="[$(kb_layout)$(bmo_be_ovw){${line#\[\{}" ;;
42
-            ',[{'*) line=",[$(kb_layout)$(bmo_be_ovw){${line#,\[\{}" ;;
169
+            '[{'*)  line="[$INFIX{${line#\[\{}" ;;
170
+            ',[{'*) line=",[$INFIX{${line#,\[\{}" ;;
43
         esac
171
         esac
44
         echo "$line"
172
         echo "$line"
45
-    done
173
+    done \
174
+  | log_post