~mil/sxmo-utils

e3f50e9d1b451b8ebcb1448a47499c64801646f8 — Miles Alan 1 year, 5 months ago 917ad2e
Only show entries to text for directories that exist; fix number bugs
2 files changed, 16 insertions(+), 9 deletions(-)

M scripts/modem/sxmo_modemdial.sh
M scripts/modem/sxmo_modemtext.sh
M scripts/modem/sxmo_modemdial.sh => scripts/modem/sxmo_modemdial.sh +1 -2
@@ 1,5 1,4 @@
#!/usr/bin/env sh
LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem
trap "gracefulexit" INT TERM

fatalerr() {


@@ 25,7 24,7 @@ dialmenu() {
	)"
	echo "$NUMBER" | grep "Close Menu" && kill 0

	NUMBER="$(echo "$NUMBER" | cut -d: -f1 tr -d '- ')"
	NUMBER="$(echo "$NUMBER" | cut -d: -f1 | tr -d -- '- ')"
	echo "$NUMBER" | grep -qE '^[+0-9]+$' || fatalerr "$NUMBER is not a number"

	echo "Attempting to dial: $NUMBER" >&2

M scripts/modem/sxmo_modemtext.sh => scripts/modem/sxmo_modemtext.sh +15 -7
@@ 48,12 48,14 @@ sendtextmenu() {

	# Prompt for number
	NUMBER="$(
		printf %b "\nCancel\n$(textcontacts)" | 
		printf %b "\nCancel\n$(sxmo_contacts.sh)" | 
		awk NF |
		sxmo_dmenu_with_kb.sh -p "Number" -fn "Terminus-20" -l 10 -c
		sxmo_dmenu_with_kb.sh -p "Number" -fn "Terminus-20" -l 10 -c |
		cut -d: -f1 |
		tr -d -- '- '
	)"
	echo "$NUMBER" | grep -E "^Cancel$" && exit 1
	echo "$NUMBER" | grep -E '[0-9]+' || err "That doesn't seem like a valid number"
	echo "$NUMBER" | grep -qE '^[+0-9]+$' || err "That doesn't seem like a valid number"

	# Compose first version of msg
	TEXT="$(editmsg "$NUMBER" 'Enter text message here')"


@@ 75,13 77,19 @@ tailtextlog() {
}

main() {
	# Display
	ENTRIES="$(printf %b "$(sxmo_contacts.sh)" | xargs -INUM echo NUM logfile)"
	ENTRIES="$(printf %b "Close Menu\nSend a Text\n$ENTRIES")"
	# E.g. only display logfiles for directories that exist and join w contact name
	ENTRIES="$(
		printf %b "Close Menu\nSend a Text\n";
		for TDIR in "$LOGDIR"/*; do
			[ -d "$TDIR" ] || continue
			NUM="$(basename "$TDIR")"
			sxmo_contacts.sh | grep -m1 "$NUM" | xargs -IL echo "L logfile"
		done
	)"
	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,}")"
	tailtextlog "$(echo "$CONTACTIDANDNUM" | cut -d: -f1)"
}

main