eeiam.in 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/bash
  2. . __FFOO_INIT__
  3. FFOO_INIPATH="__FFOO_INIPATH__"
  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 gone
  15. echo moving
  16. echo ooo
  17. echo wfh
  18. echo writing
  19. }
  20. usage() {
  21. cmd_hint=$(
  22. available_commands \
  23. | head -c -1 \
  24. | tr '\n' '|'
  25. )
  26. usage_is "$cmd_hint"
  27. }
  28. #
  29. # querying
  30. #
  31. familiars_at() {
  32. #
  33. # daemons specific to $1 location plus the rest
  34. #
  35. test -n "$1" || usagef "location"
  36. iniread -p iam.running.at.$1 iam.ini
  37. iniread -p iam.running.at.ANYPLACE iam.ini
  38. }
  39. where_i_am() {
  40. #
  41. # what is my physical location?
  42. #
  43. if=$(iniread -p iam.using.if iam.ini)
  44. gwmac=$(arp | grep "^gateway\\>.*\\<$if\$" | tr ' ' '\n' | grep :)
  45. iniread -p iam.seeing.gw.$gwmac iam.ini || echo OUT
  46. }
  47. #
  48. # subcommand handlers
  49. #
  50. i_am_afk() {
  51. #
  52. # away from keyboard; blocks until i'm back again
  53. #
  54. mocp --pause
  55. slock
  56. }
  57. i_am_at() {
  58. where_i_am
  59. }
  60. i_am_back() {
  61. #
  62. # returning to work (should be called by other subcommands)
  63. #
  64. local f fbin
  65. for f in $(familiars_at $(where_i_am));
  66. do
  67. fbin=${f/ */}
  68. pids_matching $f || $f &
  69. done
  70. klist || urxvt -e kinit
  71. }
  72. i_am_gone() {
  73. #
  74. # gone fishin'
  75. #
  76. kdestroy
  77. killall $(familiars_at $(where_i_am))
  78. i_am_afk
  79. i_am_back
  80. }
  81. i_am_moving() {
  82. #
  83. # to other train or dreamland, but localhost must sleep now
  84. #
  85. die "not implemented" # hint: use zleep
  86. }
  87. i_am_ooo() {
  88. #
  89. # too dangerous to implement
  90. #
  91. die "not implemented"
  92. }
  93. i_am_wfh() {
  94. #
  95. # too dangerous to implement
  96. #
  97. die "not implemented"
  98. }
  99. i_am_writing() {
  100. #
  101. # writing in that language
  102. #
  103. set -x
  104. DISPLAY=:0 setxkbmap $1
  105. }
  106. cmd=$1
  107. test -n "$cmd" || usage
  108. available_commands | grep -qse ^$1 || usage
  109. shift
  110. i_am_$cmd $1