~mil/sxmo-utils

ref: 9f930e742a8e5443d6ecce4252aaa78f668a50cb sxmo-utils/scripts/core/sxmo_contacts.sh -rwxr-xr-x 930 bytes
9f930e74Miles Alan Simplify sxmo_contacts.sh - use less tempfiles and join logic, output w/ colon 1 year, 10 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
#!/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
# 
# Prints in output format: "number: contact"

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

contacts() {
	RECENTCONTACTEDNUMBERSREVCHRON="$(
		cut -f3 "$LOGFILE" |
		tac |
		awk '!($0 in a){a[$0];print}' |
		sed '/^[[:space:]]*$/d'
	)"
	RECENTCONTACTEDNUMBERSREVCHRONF="$(mktemp)"
	echo "$RECENTCONTACTEDNUMBERSREVCHRON" > "$RECENTCONTACTEDNUMBERSREVCHRONF"
	printf %b "$(
		join -t"$(printf '\t')" -o1.1,2.2 -a1 -e"Unknown Number" \
		"$RECENTCONTACTEDNUMBERSREVCHRONF" "$CONTACTSFILE" |
		sed 's#\t#: #g'
	)"
	rm "$RECENTCONTACTEDNUMBERSREVCHRONF" &
}

contacts