#!/bin/sh
found=$(contacts $1)
if [ -z "$found" ]; then
#  echo "no contacts found: $@"
  exit 1
fi
if [ $(echo "$found" | wc -l) -eq 1 ]; then
  number=$(echo "$found" | awk '{print $1}')
  shift
  if [ "$1" = "-f" ]; then
    tail -f /var/spool/sms | grep "$number"
  elif [ $# -gt 0 ]; then
# TODO somewhere in here maybe if you just say a contact, you enter a thread mode where
# STDOUT is coming from sms spool and STDIN is going to sms message sending
    confirm "text $number $@" && text "$number" "$@"
  else
    grep "$number" /var/spool/sms || echo "no texts found for $number"
  fi
else
  echo "command not found: $@"
fi
