eeiam.in 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. }
  19. usage() {
  20. cmd_hint=$(
  21. available_commands \
  22. | head -c -1 \
  23. | tr '\n' '|'
  24. )
  25. usage_is "$cmd_hint"
  26. }
  27. #
  28. # querying
  29. #
  30. familiars_at() {
  31. test -n "$1" || usagef "location"
  32. iniread -p iam.needing.at.$1 iam.ini
  33. iniread -p iam.needing.at.ANY iam.ini
  34. }
  35. where_i_am() {
  36. if=$(iniread -p iam.using.if iam.ini)
  37. gwmac=$(arp | grep "^gateway\\>.*\\<$if\$" | tr ' ' '\n' | grep :)
  38. iniread -p iam.seeing.gw.$gwmac iam.ini | grep . || echo OUT
  39. }
  40. #
  41. # subcommand handlers
  42. #
  43. i_am_afk() {
  44. mocp --pause
  45. slock
  46. }
  47. i_am_at() {
  48. where_i_am
  49. }
  50. i_am_back() {
  51. local f fbin
  52. for f in $(familiars_at $(where_i_am));
  53. do
  54. fbin=${f/ */}
  55. pids_matching $f || $f &
  56. done
  57. klist || urxvt -e kinit
  58. }
  59. i_am_gone() {
  60. kdestroy
  61. killall $(familiars_at $(where_i_am))
  62. i_am_afk
  63. i_am_back
  64. }
  65. i_am_moving() {
  66. die "not implemented" # hint: use zleep
  67. }
  68. i_am_ooo() {
  69. die "not implemented"
  70. }
  71. i_am_wfh() {
  72. die "not implemented"
  73. }
  74. cmd=$1
  75. test -n "$cmd" || usage
  76. available_commands | grep -qse ^$1 || usage
  77. i_am_$cmd