eeiam.in 3.4KB

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