123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- #!/bin/bash
-
- . $(ffoom path)
-
- ffoo import pretty
- ffoo import sync
-
- ffoo import saturnin_zleep
-
-
- #
- # self help
- #
-
- available_commands() {
- echo afk
- echo at
- echo back
- echo bbl
- echo bbldone
- echo gone
- echo ooo
- echo wfh
- echo writing
- echo undocking
- echo zleeping
- }
-
- usage() {
- cmd_hint=$(
- available_commands \
- | head -c -1 \
- | tr '\n' '|'
- )
- usage_is "$cmd_hint"
- }
-
-
- #
- # querying
- #
-
- where_i_am() {
- #
- # what is my physical location?
- #
- if=$(saturnin conf -p iam.using.if)
- gwmac=$(arp | grep "^gateway\\>.*\\<$if\$" | tr ' ' '\n' | grep :)
- saturnin conf -p iam.seeing.gw.$gwmac || echo OUT
- }
-
- set_status() {
- #
- # set public status $1 by command in conf file
- #
- local what=$1
- saturnin conf -p iam.saying.like.this.$what | bash
- }
-
-
- #
- # hooks
- #
-
- run_hook() {
- local name=$1
- local cmd=$2
- local arg=$3
- saturnin conf -p iam.hooking.$name.$cmd \
- | SATURNIN_IAM_CMD=$cmd \
- SATURNIN_IAM_ARG=$arg \
- bash
- }
-
-
- #
- # subcommand handlers
- #
-
- i_am_afk() {
- #
- # away from keyboard; blocks until i'm back again
- #
- mocp --pause
- set_status "afk"
- i_am_bbldone # make sure to set lang to default before locking
- slock
- set_status "atk"
- }
-
- i_am_at() {
- #
- # Just say where I am
- #
- where_i_am
- }
-
- i_am_back() {
- #
- # returning to work (should be called by other subcommands)
- #
- set_status "back"
- klist -s || urxvt -e kinit
- }
-
- i_am_bbl() {
- #
- # changing language
- #
- local cur=$(setxkbmap -v | grep '^symbols: ' | cut -d+ -f2)
- local all="$(saturnin conf -p iam.typing.lang)"
- local def="$(saturnin conf -1 -p iam.typing.lang)"
- local nxt=$(
- echo -e "$all\n$all" \
- | grep -m 1 -A 1 $cur \
- | tail -1
- )
- test -z "$nxt" && nxt=$def
- test -z "$nxt" && nxt=us
- debug -v all def cur nxt
- setxkbmap "$nxt"
- }
-
- i_am_bbldone() {
- #
- # changing language back to normal
- #
- setxkbmap "$(saturnin conf -1 -p iam.typing.lang)"
- }
-
- i_am_gone() {
- #
- # gone fishin'
- #
- kdestroy
- ssh-add -D
- set_status "gone"
- i_am_afk
- i_am_back
- }
-
- i_am_ooo() {
- #
- # too dangerous to implement
- #
- die "not implemented"
- }
-
- i_am_wfh() {
- #
- # too dangerous to implement
- #
- die "not implemented"
- }
-
- i_am_writing() {
- #
- # writing in that language
- #
- set -x
- DISPLAY=:0 setxkbmap $1
- }
-
- i_am_undocking() {
- #
- # i.e. hibernated
- #
- saturnin conf -p iam.undocking.like | bash -
- }
-
- i_am_zleeping() {
- #
- # i.e. hibernated
- #
- set_status "zleeping"
- zleep
- i_am_back
- }
-
- cmd=$1
-
- test -n "$cmd" || usage
-
- available_commands | grep -qse ^$1 || usage
-
- shift
-
- run_hook before $cmd $1
- i_am_$cmd $1
- run_hook after $cmd $1
|