~mil/sxmo-utils

ref: f95cb5198470c150646f10dee32b202e35ed0ba2 sxmo-utils/scripts/core/sxmo_contacts.sh -rwxr-xr-x 1.3 KiB
f95cb519Anjandev Momi add contacts.tsv integration to call and text apps 1 year, 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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"