#!/usr/bin/env zsh

cd

# Store config files and other shared data
StoreShared() {
  # sort addressbook
  test -f $ABOOK.master && Which - abook && test $ABOOK -nt $CSVBOOK &&
    abook --convert --outfile -  --outformat allcsv --infile $ABOOK --informat abook | sort -r > $CSVBOOK
  # backup configs
  test -x =darcs && darcs record -a -m "`date`/`hostname`" && darcs push -a -q
}

# Stop ssh-agent
StopAgent() { # immediate_kill
  eval `ssh-agent -k`
  test -z "$1" || killall -HUP ssh-agent
}

case "$0" in
  -*)			# login.shell
      test -r "$0.local" && . "$0.local" || :
      test -z "$SSH_AUTH_SOCK" || StoreShared
      StopAgent
    ;;
  *)			# other: force agent to stop
      StopAgent /dev/null
    ;;
esac

echo "Done."
sleep 1
