eeiam 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #!/bin/bash
  2. . <(ffoom init)
  3. ffoo import core
  4. ffoo import recon
  5. #
  6. # self help
  7. #
  8. available_commands() {
  9. echo afk
  10. echo at
  11. echo back
  12. echo bbl
  13. echo bbldone
  14. echo deaf
  15. echo deafnomore
  16. echo gone
  17. echo listening
  18. echo moving
  19. echo ooo
  20. echo wfh
  21. echo writing
  22. }
  23. usage() {
  24. cmd_hint=$(
  25. available_commands \
  26. | head -c -1 \
  27. | tr '\n' '|'
  28. )
  29. usage_is "$cmd_hint"
  30. }
  31. #
  32. # querying
  33. #
  34. familiars_at() {
  35. #
  36. # daemons specific to $1 location plus the rest
  37. #
  38. test -n "$1" || usagef "location"
  39. eeini -p iam.running.at.$1
  40. eeini -p iam.running.at.ANYPLACE
  41. }
  42. where_i_am() {
  43. #
  44. # what is my physical location?
  45. #
  46. if=$(eeini -p iam.using.if)
  47. gwmac=$(arp | grep "^gateway\\>.*\\<$if\$" | tr ' ' '\n' | grep :)
  48. eeini -p iam.seeing.gw.$gwmac || echo OUT
  49. }
  50. start_familiar() {
  51. #
  52. # start familiar as indicated by ini file (unless running)
  53. #
  54. local f=$1
  55. pids_matching $f && return 0
  56. local like=$(eeini -p iam.starting.like.this.$f)
  57. debug -v f like
  58. if test -n "$like";
  59. then
  60. $like &
  61. else $f &
  62. fi
  63. }
  64. set_status() {
  65. #
  66. # set public status $1 by command in ini file
  67. #
  68. local what=$1
  69. eeini -p iam.saying.like.this.$what | bash
  70. }
  71. sound_is_muted() {
  72. #
  73. # At least one playback channel is muted
  74. #
  75. local master_status="$(amixer get Master)"
  76. echo "$master_status" \
  77. | grep "Playback channels" \
  78. | sed -e 's/.*: //; s/ - /\n/' \
  79. | while read chname
  80. do
  81. grep -e "^ *$chname" <<<"$master_status"
  82. done \
  83. | grep -qse '\[off\]$'
  84. }
  85. #
  86. # subcommand handlers
  87. #
  88. i_am_afk() {
  89. #
  90. # away from keyboard; blocks until i'm back again
  91. #
  92. mocp --pause
  93. set_status "afk"
  94. slock
  95. set_status "atk"
  96. }
  97. i_am_at() {
  98. #
  99. # Just say where I am
  100. #
  101. where_i_am
  102. }
  103. i_am_back() {
  104. #
  105. # returning to work (should be called by other subcommands)
  106. #
  107. local f
  108. for f in $(familiars_at $(where_i_am));
  109. do
  110. start_familiar $f
  111. done
  112. set_status "back"
  113. klist || urxvt -e kinit
  114. }
  115. i_am_bbl() {
  116. #
  117. # changing language
  118. #
  119. local cur=$(setxkbmap -v | grep '^symbols: ' | cut -d+ -f2)
  120. local all="$(eeini -p iam.typing.lang)"
  121. local def="$(eeini -1 -p iam.typing.lang)"
  122. local nxt=$(
  123. echo -e "$all\n$all" \
  124. | grep -m 1 -A 1 $cur \
  125. | tail -1
  126. )
  127. test -z "$nxt" && nxt=$def
  128. test -z "$nxt" && nxt=us
  129. debug -v all def cur nxt
  130. setxkbmap "$nxt"
  131. }
  132. i_am_bbldone() {
  133. #
  134. # changing language back to normal
  135. #
  136. setxkbmap "$(eeini -1 -p iam.typing.lang)"
  137. }
  138. i_am_deaf() {
  139. amixer -q sset Master 5%+
  140. }
  141. i_am_deafnomore() {
  142. amixer -q sset Master 5%-
  143. }
  144. i_am_gone() {
  145. #
  146. # gone fishin'
  147. #
  148. kdestroy
  149. ssh-add -D
  150. set_status "gone"
  151. i_am_afk
  152. i_am_back
  153. }
  154. i_am_listening() {
  155. if sound_is_muted;
  156. then
  157. amixer -q sset Master unmute;
  158. else
  159. amixer -q sset Master mute;
  160. fi
  161. }
  162. i_am_moving() {
  163. #
  164. # to other train or dreamland, but localhost must sleep now
  165. #
  166. die "not implemented" # hint: use zleep
  167. }
  168. i_am_ooo() {
  169. #
  170. # too dangerous to implement
  171. #
  172. die "not implemented"
  173. }
  174. i_am_wfh() {
  175. #
  176. # too dangerous to implement
  177. #
  178. die "not implemented"
  179. }
  180. i_am_writing() {
  181. #
  182. # writing in that language
  183. #
  184. set -x
  185. DISPLAY=:0 setxkbmap $1
  186. }
  187. cmd=$1
  188. test -n "$cmd" || usage
  189. available_commands | grep -qse ^$1 || usage
  190. shift
  191. i_am_$cmd $1