From 87d86b7cf047e32208b1f6bc51d28d00a0883543 Mon Sep 17 00:00:00 2001 From: Stacy Harper Date: Sat, 18 Sep 2021 11:55:25 +0200 Subject: [PATCH] Allow phone number find in send text submenu This allow the user to use a non formated phone number. We split valid number check in a dedicated script to allow this. --- scripts/core/sxmo_contactmenu.sh | 25 +------------------------ scripts/core/sxmo_validnumber.sh | 25 +++++++++++++++++++++++++ scripts/modem/sxmo_modemtext.sh | 8 ++++---- 3 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 scripts/core/sxmo_validnumber.sh diff --git a/scripts/core/sxmo_contactmenu.sh b/scripts/core/sxmo_contactmenu.sh index 3fd3ed6..8fca2df 100755 --- a/scripts/core/sxmo_contactmenu.sh +++ b/scripts/core/sxmo_contactmenu.sh @@ -3,29 +3,6 @@ # shellcheck source=scripts/core/sxmo_common.sh . "$(dirname "$0")/sxmo_common.sh" -valid_number() { - if pn valid "$1"; then - echo "$1" - return - fi - - REFORMATTED="$(pn find ${DEFAULT_COUNTRY:+-c "$DEFAULT_COUNTRY"} "$1")" - if pn valid "$REFORMATTED"; then - echo "$REFORMATTED" - return - fi - - notify-send "\"$1\" is not a valid phone number" - - PICKED="$(printf "Ok\nUse as it is\n" | dmenu -p "Invalid Number")" - if [ "$PICKED" = "Use as it is" ]; then - echo "$1" - return - fi - - exit -} - newcontact() { name="$(echo | sxmo_dmenu_with_kb.sh -p "$icon_usr Name")" number= @@ -72,7 +49,7 @@ editcontactnumber() { editcontact "$1" return fi - PICKED="$(valid_number "$PICKED")" + PICKED="$(sxmo_validnumber.sh "$PICKED")" done newcontact="$PICKED $oldname" diff --git a/scripts/core/sxmo_validnumber.sh b/scripts/core/sxmo_validnumber.sh new file mode 100644 index 0000000..c68cb0a --- /dev/null +++ b/scripts/core/sxmo_validnumber.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env sh + +# shellcheck source=scripts/core/sxmo_common.sh +. "$(dirname "$0")/sxmo_common.sh" + +if pn valid "$1"; then + printf %s "$1" + exit +fi + +REFORMATTED="$(pn find ${DEFAULT_COUNTRY:+-c "$DEFAULT_COUNTRY"} "$1")" +if pn valid "$REFORMATTED"; then + printf %s "$REFORMATTED" + exit +fi + +notify-send "\"$1\" is not a valid phone number" + +PICKED="$(printf "Ok\nUse as it is\n" | sxmo_dmenu.sh -p "Invalid Number")" +if [ "$PICKED" = "Use as it is" ]; then + printf %s "$1" + exit +fi + +exit 1 diff --git a/scripts/modem/sxmo_modemtext.sh b/scripts/modem/sxmo_modemtext.sh index d345d15..f13bb39 100755 --- a/scripts/modem/sxmo_modemtext.sh +++ b/scripts/modem/sxmo_modemtext.sh @@ -29,12 +29,12 @@ choosenumbermenu() { )" fi - if echo "$NUMBER" | grep -q "Cancel"; then + if printf %s "$NUMBER" | grep -q "Cancel"; then exit 1 - elif ! echo "$NUMBER" | grep -qE '^[+0-9]+$'; then - notify-send "That doesn't seem like a valid number" + elif NUMBER="$(sxmo_validnumber.sh "$NUMBER")"; then + printf %s "$NUMBER" else - echo "$NUMBER" + notify-send "That doesn't seem like a valid number" fi }