From e3f50e9d1b451b8ebcb1448a47499c64801646f8 Mon Sep 17 00:00:00 2001 From: Miles Alan Date: Mon, 29 Jun 2020 12:57:42 -0500 Subject: [PATCH] Only show entries to text for directories that exist; fix number bugs --- scripts/modem/sxmo_modemdial.sh | 3 +-- scripts/modem/sxmo_modemtext.sh | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/scripts/modem/sxmo_modemdial.sh b/scripts/modem/sxmo_modemdial.sh index f6587e0..c4440ee 100755 --- a/scripts/modem/sxmo_modemdial.sh +++ b/scripts/modem/sxmo_modemdial.sh @@ -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 diff --git a/scripts/modem/sxmo_modemtext.sh b/scripts/modem/sxmo_modemtext.sh index 44a049e..b23700c 100755 --- a/scripts/modem/sxmo_modemtext.sh +++ b/scripts/modem/sxmo_modemtext.sh @@ -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