#!/bin/dash # prepend i3status with more stuff I3STAPLUS__SSHAK_NEED=${I3STAPLUS__SSHAK_NEED:-F} I3STAPLUS__LOG=${I3STAPLUS__LOG:-true} I3STAPLUS__LOGDIR=${I3STAPLUS__LOGDIR:-"$HOME/.local/share/i3staplus/logs"} I3STAPLUS__KPRINC_NEED=${I3STAPLUS__KPRINC_NEED:-T} kb_layout() { local layout local color layout=$( setxkbmap -query \ | awk '/layout/{print $2}' ) case $layout in us) color='' ;; *) color=',"color": "#ff0000"' ;; esac printf '{"full_text": " %s"%s},' \ "$layout" "$color" } bmo_be_ovw() { local ovw_path=.local/share/bmo/be/important.state local ovw local color test -s "$ovw_path" || return 0 ovw=$(cat "$ovw_path") case $ovw in *%gone) color=',"color": "#ff0000"' ;; *%mtg) color=',"color": "#ff0000"' ;; *%onbreak) color=',"color": "#33aa55"' ;; *%working) color=',"color": "#cccccc"' ;; *) color='' ;; esac printf '{"full_text": " %s"%s},' \ "$ovw" "$color" } morf_V() { return 0 local ver local err=F local color ver=$(morf -V) || err=T test -n "$ver" || ver="(none)" case $err:$ver in T:*) color=',"color": "#ff0000"' ;; *:*+*) color=',"color": "#f08000"' ;; esac printf '{"full_text": "ⓜ %s"%s},' \ "$ver" "$color" } gibrs() { local out out=$(showgbr) test -n "$out" || return 0 printf '{"full_text": "ⓖ %s"},' \ "$out" } kprinc() { local principal local err=F local color=',"color": "%cccccc"' principal=$( klist -A 2>/dev/null \ | grep -m1 '^Default principal: ' \ | cut -d' ' -f3- \ | tr '@' '\n' \ | tr '.' '\n' \ | grep -o '^.' \ | tr -d '\n' ) principal_n=$( klist -A 2>/dev/null \ | grep -c '^Default principal: ' ) case "$principal_n" in 0) principal='(n)' color=',"color": "#f08000"' ;; 1) : ;; *) principal="$principal+" ;; esac printf '{"full_text": "ⓚ %s"%s},' \ "$principal" "$color" } sshak() { local keys_desc local keys_n local err=F local color=',"color": "#cccccc"' keys_n=$( ssh-add -l \ | grep -cv 'The agent has no identities' ) keys_desc=$( ssh-add -l \ | grep -v 'The agent has no identities' \ | while read -r k_size k_id k_cmt k_alg; do shortcmt=$( echo "$k_cmt" \ | sed -E ' s/([^@]).*@([^ ]).*/\1@\2/ ' ) test -n "$shortcmt" \ && echo "$shortcmt" \ && continue echo "$k_id" | sed -E 's/.*:(...).*/\1/' done ) case "$keys_n:$I3STAPLUS__SSHAK_NEED" in 0:T) color=',"color": "#f08000"'; keys_desc='(n)' ;; 0:*) keys_desc='(n)' ;; # *) color=',"color": "#cccccc"' ;; esac printf '{"full_text": "ⓢ %s"%s},' \ "$keys_desc" "$color" } m_sprintn() { return 0 local sprintn local color local ccode sprintn=$(scrumq) case $sprintn in *r3) ccode='#ffddcc' ;; # Mon *r2) ccode='#ffaa99' ;; *r1) ccode='#ff7766' ;; *r0) ccode='#ff3333' ;; *) ccode='' ;; esac test -n "$ccode" && color=',"color": "'"$ccode"'"' printf '{"full_text": " %s"%s},' \ "$sprintn" "$color" } if test "x$I3STAPLUS__LOG" = "xtrue"; then mkdir -p "$I3STAPLUS__LOGDIR" log_pre() { tee "$I3STAPLUS__LOGDIR/debug-pre.json" } log_post() { tee "$I3STAPLUS__LOGDIR/debug-post.json" } else log_pre() { cat } log_post() { cat } fi i3status \ | log_pre \ | while true do read -r line INFIX="$(kb_layout)$(bmo_be_ovw)$(gibrs)$(kprinc)$(sshak)" case $line in '[{'*) line="[$INFIX{${line#\[\{}" ;; ',[{'*) line=",[$INFIX{${line#,\[\{}" ;; esac echo "$line" done \ | log_post