~mil/sxmo-utils

87d86b7cf047e32208b1f6bc51d28d00a0883543 — Stacy Harper a month ago 55985a8
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.
M scripts/core/sxmo_contactmenu.sh => scripts/core/sxmo_contactmenu.sh +1 -24
@@ 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"

A scripts/core/sxmo_validnumber.sh => scripts/core/sxmo_validnumber.sh +25 -0
@@ 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

M scripts/modem/sxmo_modemtext.sh => scripts/modem/sxmo_modemtext.sh +4 -4
@@ 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
}