#!/bin/bash . $(ffoom path) ffoo import pretty ffoo import recon # # self help # available_commands() { echo afk echo at echo back echo bbl echo bbldone echo deaf echo deafnomore echo gone echo listening echo moving echo ooo echo wfh echo writing } usage() { cmd_hint=$( available_commands \ | head -c -1 \ | tr '\n' '|' ) usage_is "$cmd_hint" } # # querying # familiars_at() { # # daemons specific to $1 location plus the rest # test -n "$1" || usagef "location" saturnin conf -p iam.running.at.$1 saturnin conf -p iam.running.at.ANYPLACE } 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 } start_familiar() { # # start familiar as indicated by conf file (unless running) # local f=$1 pids_matching $f && return 0 local like=$(saturnin conf -p iam.starting.like.this.$f) debug -v f like if test -n "$like"; then $like & else $f & fi } set_status() { # # set public status $1 by command in conf file # local what=$1 saturnin conf -p iam.saying.like.this.$what | bash } sound_is_muted() { # # At least one playback channel is muted # local master_status="$(amixer get Master)" echo "$master_status" \ | grep "Playback channels" \ | sed -e 's/.*: //; s/ - /\n/' \ | while read chname do grep -e "^ *$chname" <<<"$master_status" done \ | grep -qse '\[off\]$' } # # 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) # local f for f in $(familiars_at $(where_i_am)); do start_familiar $f done set_status "back" klist || 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_deaf() { amixer -q sset Master 5%+ } i_am_deafnomore() { amixer -q sset Master 5%- } i_am_gone() { # # gone fishin' # kdestroy ssh-add -D set_status "gone" i_am_afk i_am_back } i_am_listening() { if sound_is_muted; then amixer -q sset Master unmute; else amixer -q sset Master mute; fi } i_am_moving() { # # to other train or dreamland, but localhost must sleep now # die "not implemented" # hint: use zleep } 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 } cmd=$1 test -n "$cmd" || usage available_commands | grep -qse ^$1 || usage shift i_am_$cmd $1