~mil/sxmo-utils

ref: 65d9d60ff15c62554b1589aad1163d8c1d31328b sxmo-utils/scripts/core/sxmo_contacts.sh -rwxr-xr-x 1.1 KiB
65d9d60fReed Wade Add more contacts choice to contact list 1 year, 2 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
36
37
38
39
40
41
#!/usr/bin/env sh
# This script prints in reverse chronological order unique entries from the
# modem log merged with contact names defined in contacts file tsv.
#   Wherein $CONTACTSFILE is tsv with two fields: number\tcontact name
#   Wherein $LOGFILE is *sorted* tsv with three fields: date\tevt\tnumber
#
#   number should be a full phone number starting with + and the country number
# 
# Prints in output format: "number: contact"

CONTACTSFILE="$XDG_CONFIG_HOME"/sxmo/contacts.tsv
LOGFILE="$XDG_CONFIG_HOME"/sxmo/modem/modemlog.tsv

contacts() {
	grep -q . "$CONTACTSFILE" || echo " " > "$CONTACTSFILE"
	RECENTCONTACTEDNUMBERSREVCHRON="$(
		cut -f3 "$LOGFILE" |
		tac |
		awk '!($0 in a){a[$0]; if (substr($0,1,1) == "+") print}' |
		sed '/^[[:space:]]*$/d'
	)"
	printf %b "$RECENTCONTACTEDNUMBERSREVCHRON" | awk -F'\t' '
		FNR==NR{a[$1]=$2; next}
		{
			if (!a[$1]) a[$1] = "Unknown Number";
			if (substr($0,1,1) == "+") print $0 ": " a[$1]
		}
	' "$CONTACTSFILE" -
}

all_contacts() {
	cat "$CONTACTSFILE" | awk -F'\t' '{
		if (substr($0,1,1) == "+") print $1 ": " $2
	}' | sort -f -k 2
}

if [ "$1" = "--all" ]; then
	all_contacts
else
	contacts
fi