diff --git a/configs/appcfg/xinit_template b/configs/appcfg/xinit_template index f9a7958..c497864 100644 --- a/configs/appcfg/xinit_template +++ b/configs/appcfg/xinit_template @@ -24,6 +24,11 @@ amixer set "Line Out" 50% # Play a funky startup tune #mpv --quiet --no-video ~/welcome.ogg & +# You will sometime get SMS or calls from not +# country code prefixed phone numbers. To ensure +# we match your contacts, we will use this one. +#export DEFAULT_NUMBER_PREFIX=+33 + # turn on modemmonitor on login # Note: if the modemmonitor is not on you can # not receive texts/calls! diff --git a/scripts/core/sxmo_contactmenu.sh b/scripts/core/sxmo_contactmenu.sh index 5655192..2cbe78e 100755 --- a/scripts/core/sxmo_contactmenu.sh +++ b/scripts/core/sxmo_contactmenu.sh @@ -3,9 +3,23 @@ # shellcheck source=scripts/core/sxmo_common.sh . "$(dirname "$0")/sxmo_common.sh" +valid_number() { + number="$(echo "$1" | sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/")" + + if echo "$number" | grep -q "^+[0-9]\{11\}$"; then + echo "$number" + else + notify-send "\"$number\" is not a valid phone number" + notify-send "Valid format is \"+[0-9]{11}\"" + fi +} + newcontact() { name="$(echo | sxmo_dmenu_with_kb.sh -c -l 2 -p "$icon_usr Name")" - number="$(echo | sxmo_dmenu_with_kb.sh -c -l 2 -p "$icon_phl Number")" + while [ -z "$number" ]; do + number="$(echo | sxmo_dmenu_with_kb.sh -c -l 2 -p "$icon_phl Number")" + number="$(valid_number "$number")" + done PICKED="$number $name" # now act like if we picked this new contact echo "$PICKED" >> "$CONTACTFILE" @@ -35,18 +49,22 @@ editcontactnumber() { oldname="$(echo "$1" | cut -d" " -f2)" ENTRIES="$(printf %b "Old number: $oldnumber")" - PICKED="$( - echo "$ENTRIES" | - sxmo_dmenu_with_kb.sh -c -l 3 -p "$icon_edt Edit Contact" - )" - - if ! echo "$PICKED" | grep -q "^Old number: "; then - newcontact="$PICKED $oldname" - sed -i "s/^$1$/$newcontact/" "$CONTACTFILE" - set -- "$newcontact" - fi + PICKED= # already used var name + while [ -z "$PICKED" ]; do + PICKED="$( + echo "$ENTRIES" | + sxmo_dmenu_with_kb.sh -c -l 3 -p "$icon_edt Edit Contact" + )" + if echo "$PICKED" | grep -q "^Old number: "; then + editcontact "$1" + return + fi + PICKED="$(valid_number "$PICKED")" + done - editcontact "$1" + newcontact="$PICKED $oldname" + sed -i "s/^$1$/$newcontact/" "$CONTACTFILE" + editcontact "$newcontact" } deletecontact() { diff --git a/scripts/core/sxmo_contacts.sh b/scripts/core/sxmo_contacts.sh index 85c1972..886dc22 100755 --- a/scripts/core/sxmo_contacts.sh +++ b/scripts/core/sxmo_contacts.sh @@ -20,6 +20,7 @@ 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' diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh index d5ba98e..bbac2fc 100755 --- a/scripts/modem/sxmo_modemmonitor.sh +++ b/scripts/modem/sxmo_modemmonitor.sh @@ -47,11 +47,9 @@ lookupcontactname() { if [ "$1" = "--" ]; then echo "Unknown number" else - NUMBER="$1" + NUMBER="$(echo "$1" | sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/")" CONTACT=$(sxmo_contacts.sh --all | - grep "$NUMBER:" | #this is not an exact match but a suffix match - #which also works if the + and country code are missing - #but may lead to false positives in rare cases (short numbers) + grep "^$NUMBER:" | cut -d':' -f 2 | sed 's/^[ \t]*//;s/[ \t]*$//' #strip leading/trailing whitespace )