My dotfiles. Period.

i3staplus 3.9KB

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