My dotfiles. Period.

i3staplus 4.2KB

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