From e444553ae4aa201383341f752413d1c0be51edb7 Mon Sep 17 00:00:00 2001 From: Stacy Harper Date: Sat, 15 May 2021 18:20:35 +0200 Subject: [PATCH] Optimize sxmo_modemtext contact listing When you number of conversation start to grow, it rapidly take some seconds for the menu to open itself. The [ -d "folder" ] test really is uneficient. This simplify this part as we now ask sxmo_contacts to only list texted contacts. --- scripts/core/sxmo_contacts.sh | 35 +++++++++++++++++++++++---------- scripts/modem/sxmo_modemtext.sh | 5 +---- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/scripts/core/sxmo_contacts.sh b/scripts/core/sxmo_contacts.sh index b01cdf1..003f2e9 100755 --- a/scripts/core/sxmo_contacts.sh +++ b/scripts/core/sxmo_contacts.sh @@ -16,16 +16,13 @@ CONTACTSFILE="$XDG_CONFIG_HOME"/sxmo/contacts.tsv LOGFILE="$XDG_DATA_HOME"/sxmo/modem/modemlog.tsv -contacts() { - grep -q . "$CONTACTSFILE" || echo " " > "$CONTACTSFILE" - RECENTCONTACTEDNUMBERSREVCHRON="$( - cut -f3 "$LOGFILE" | - sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/" | - tac | - awk '!($0 in a){a[$0]; print}' | - sed '/^[[:space:]]*$/d' - )" - printf %b "$RECENTCONTACTEDNUMBERSREVCHRON" | awk -F'\t' ' +prepare_contacts_list() { + cut -f3 | + sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/" | + tac | + awk '!($0 in a){a[$0]; print}' | + sed '/^[[:space:]]*$/d' | + awk -F'\t' ' FNR==NR{a[$1]=$2; next} { if (!a[$1]) a[$1] = "Unknown Number"; @@ -34,6 +31,18 @@ contacts() { ' "$CONTACTSFILE" - } +contacts() { + prepare_contacts_list < "$LOGFILE" +} + +texted_contacts() { + grep "\(recv\|sent\)_txt" "$LOGFILE" | prepare_contacts_list +} + +called_contacts() { + grep "call_\(pickup\|start\)" "$LOGFILE" | prepare_contacts_list +} + all_contacts() { awk -F'\t' '{ print $1 ": " $2 @@ -47,10 +56,16 @@ unknown_contacts() { | grep "^+[0-9]\{9,14\}$" } +[ -f "$CONTACTSFILE" ] || touch "$CONTACTSFILE" + if [ "$1" = "--all" ]; then all_contacts elif [ "$1" = "--unknown" ]; then unknown_contacts +elif [ "$1" = "--texted" ]; then + texted_contacts +elif [ "$1" = "--called" ]; then + called_contacts else contacts fi diff --git a/scripts/modem/sxmo_modemtext.sh b/scripts/modem/sxmo_modemtext.sh index 84ba416..802a38b 100755 --- a/scripts/modem/sxmo_modemtext.sh +++ b/scripts/modem/sxmo_modemtext.sh @@ -89,10 +89,7 @@ readtextmenu() { # E.g. only display logfiles for directories that exist and join w contact name ENTRIES="$( printf %b "$icon_cls Close Menu\n$icon_edt Send a Text\n"; - sxmo_contacts.sh | while read -r CONTACT; do - [ -d "$LOGDIR"/"$(printf %b "$CONTACT" | cut -d: -f1)" ] || continue - printf %b "$CONTACT" | xargs -IL echo "L logfile" - done + sxmo_contacts.sh --texted | xargs -IL echo "L logfile" )" PICKED="$(printf %b "$ENTRIES" | dmenu -p Texts -c -l 10 -i)" || exit