eeiam.in 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 gone
  16. echo moving
  17. echo ooo
  18. echo wfh
  19. echo writing
  20. }
  21. usage() {
  22. cmd_hint=$(
  23. available_commands \
  24. | head -c -1 \
  25. | tr '\n' '|'
  26. )
  27. usage_is "$cmd_hint"
  28. }
  29. #
  30. # querying
  31. #
  32. familiars_at() {
  33. #
  34. # daemons specific to $1 location plus the rest
  35. #
  36. test -n "$1" || usagef "location"
  37. iniread -p iam.running.at.$1
  38. iniread -p iam.running.at.ANYPLACE
  39. }
  40. where_i_am() {
  41. #
  42. # what is my physical location?
  43. #
  44. if=$(iniread -p iam.using.if)
  45. gwmac=$(arp | grep "^gateway\\>.*\\<$if\$" | tr ' ' '\n' | grep :)
  46. iniread -p iam.seeing.gw.$gwmac || echo OUT
  47. }
  48. start_familiar() {
  49. #
  50. # start familiar as indicated by ini file (unless running)
  51. #
  52. local f=$1
  53. pids_matching $f && return 0
  54. local like=$(iniread -p iam.starting.like.this.$f)
  55. debug -v f like
  56. if test -n "$like";
  57. then
  58. $like &
  59. else $f &
  60. fi
  61. }
  62. set_status() {
  63. #
  64. # set public status $1 by command in ini file
  65. #
  66. local what=$1
  67. iniread -p iam.saying.like.this.$what | bash
  68. }
  69. #
  70. # subcommand handlers
  71. #
  72. i_am_afk() {
  73. #
  74. # away from keyboard; blocks until i'm back again
  75. #
  76. mocp --pause
  77. set_status "afk"
  78. slock
  79. set_status "atk"
  80. }
  81. i_am_at() {
  82. #
  83. # Just say where I am
  84. #
  85. where_i_am
  86. }
  87. i_am_back() {
  88. #
  89. # returning to work (should be called by other subcommands)
  90. #
  91. local f
  92. for f in $(familiars_at $(where_i_am));
  93. do
  94. start_familiar $f
  95. done
  96. set_status "back"
  97. klist || urxvt -e kinit
  98. }
  99. i_am_bbl() {
  100. #
  101. # changing language
  102. #
  103. local cur=$(setxkbmap -v | grep '^symbols: ' | cut -d+ -f2)
  104. local all="$(iniread -p iam.typing.lang)"
  105. local def="$(iniread -1 -p iam.typing.lang)"
  106. local nxt=$(
  107. echo -e "$all\n$all" \
  108. | grep -m 1 -A 1 $cur \
  109. | tail -1
  110. )
  111. test -z "$nxt" && nxt=$def
  112. test -z "$nxt" && nxt=us
  113. debug -v all def cur nxt
  114. setxkbmap "$nxt"
  115. }
  116. i_am_gone() {
  117. #
  118. # gone fishin'
  119. #
  120. kdestroy
  121. ssh-add -D
  122. set_status "gone"
  123. i_am_afk
  124. i_am_back
  125. }
  126. i_am_moving() {
  127. #
  128. # to other train or dreamland, but localhost must sleep now
  129. #
  130. die "not implemented" # hint: use zleep
  131. }
  132. i_am_ooo() {
  133. #
  134. # too dangerous to implement
  135. #
  136. die "not implemented"
  137. }
  138. i_am_wfh() {
  139. #
  140. # too dangerous to implement
  141. #
  142. die "not implemented"
  143. }
  144. i_am_writing() {
  145. #
  146. # writing in that language
  147. #
  148. set -x
  149. DISPLAY=:0 setxkbmap $1
  150. }
  151. cmd=$1
  152. test -n "$cmd" || usage
  153. available_commands | grep -qse ^$1 || usage
  154. shift
  155. i_am_$cmd $1