My dotfiles. Period.

i3staplus 4.1KB

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