add contacts.tsv integration to call and text apps

Signed-off-by: Miles Alan <m@milesalan.com>
master
Anjandev Momi 5 years ago committed by Miles Alan
parent ff9ddcb634
commit f95cb51984
  1. 35
      scripts/core/sxmo_contacts.sh
  2. 6
      scripts/modem/sxmo_modemcall.sh
  3. 9
      scripts/modem/sxmo_modemdial.sh
  4. 15
      scripts/modem/sxmo_modemtext.sh

@ -0,0 +1,35 @@
#!/usr/bin/env sh
# This script is a helper script for sxmo_modemtext.sh and sxmo_modemcall.sh
# When this script is called from a terminal, it prints the phone's known
# contacts in reverse chronological order of contact.
CONTACTSFILE="$XDG_CONFIG_HOME"/sxmo/contacts.tsv
LOGFILE="$XDG_CONFIG_HOME"/sxmo/modem/modemlog.tsv
SORTED_CONTACTS="$(mktemp)"
sort -k2 "$CONTACTSFILE" > "$SORTED_CONTACTS"
# Add names to numbers called/texted in modemlog
tab=$(printf '\t')
CALLED="$(sed 's/ +1//' "$LOGFILE" | sort -u -k3,3 |
join -t "$tab" -1 2 -2 3 -o 2.1,1.1,2.3 -a 2 "$SORTED_CONTACTS" - |
sort -rk1 | cut -f2,3 | sed 's/^\t//')"
# add all known contacts
ALL_DATA=$(printf %b "$CALLED\n$(cat "$CONTACTSFILE")" | nl)
## We must now remove contacts that have called/texted from the ALL_DATA list
# If there is a name for the contact, the row will have 3 columns
# if there is no name for the contact, the row will only have 2 columns.
# To make sure data lines up, remove contacts called and texted duplicate named contacts seperately
NAMED_ORDER="$(echo "$ALL_DATA" | awk 'NF==3{print}{}' | sort -uk3)"
NONAME="$(echo "$ALL_DATA" | awk 'NF==2{print}{}')"
RES=$(printf %b "$NAMED_ORDER\n$NONAME" | sort -k1 | cut -f2,3)
echo "$RES"
printf %b "$RES" | grep -q 8042221111 || echo "Test Number 8042221111"
rm "$SORTED_CONTACTS"

@ -22,12 +22,6 @@ modem_n() {
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2
}
contacts() {
RES="$(cut -f3 "$LOGDIR/modemlog.tsv" | sort | uniq | awk NF)"
echo "$RES"
printf %b "$RES" | grep -q 8042221111 || echo "Test Number 8042221111"
}
modem_cmd_errcheck() {
RES="$(mmcli "$@" 2>&1)"
OK="$?"

@ -17,7 +17,7 @@ modem_n() {
}
dialmenu() {
CONTACTS="$(contacts)"
CONTACTS="$(sxmo_contacts.sh)"
NUMBER="$(
printf %b "Close Menu\n$CONTACTS" |
grep . |
@ -25,7 +25,12 @@ dialmenu() {
)"
echo "$NUMBER" | grep "Close Menu" && kill 0
NUMBER="$(echo "$NUMBER" | awk -F' ' '{print $NF}' | tr -d -)"
NUMBER="$(
echo "$NUMBER" |
awk -F' ' '{print $NF}' |
tr -d - |
cut -f2
)"
echo "$NUMBER" | grep -qE '^[+0-9]+$' || fatalerr "$NUMBER is not a number"
echo "Attempting to dial: $NUMBER" >&2

@ -13,11 +13,6 @@ modem_n() {
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2
}
textcontacts() {
# TODO: is find automatically sorted by timestamp?
find "$LOGDIR"/* -type d -maxdepth 1 | awk -F'/' '{print $NF}' | tac
}
editmsg() {
TMP="$(mktemp --suffix "$1_msg")"
echo "$2" > "$TMP"
@ -81,12 +76,12 @@ tailtextlog() {
main() {
# Display
ENTRIES="$(printf %b "$(textcontacts)" | xargs -INUM echo NUM logfile)"
ENTRIES="$(printf %b "$(sxmo_contacts.sh)" | xargs -INUM echo NUM logfile)"
ENTRIES="$(printf %b "Close Menu\nSend a Text\n$ENTRIES")"
NUMBER="$(printf %b "$ENTRIES" | dmenu -p Texts -c -fn Terminus-20 -l 10)"
echo "$NUMBER" | grep "Close Menu" && exit 1
echo "$NUMBER" | grep "Send a Text" && sendtextmenu && exit 1
tailtextlog "$(echo "$NUMBER" | sed 's/ logfile//g')"
CONTACTIDANDNUM="$(printf %b "$ENTRIES" | dmenu -p Texts -c -fn Terminus-20 -l 10)"
echo "$CONTACTIDANDNUM" | grep "Close Menu" && exit 1
echo "$CONTACTIDANDNUM" | grep "Send a Text" && sendtextmenu && exit 1
tailtextlog "$(echo "$CONTACTIDANDNUM" | grep -Eo "[0-9]{3,}")"
}
main

Loading…
Cancel
Save