~mil/sxmo-utils

a3e4dc0fa47d4b73bf2c3d0f138e253abdbe982c — Stacy Harper 7 months ago 33e6ce1
Make all sxmo menu SSH mode compatible

We then simplify the sxmo_modemtext that was already using SSH related
behaviors.

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
M scripts/core/sxmo_bluetoothmenu.sh => scripts/core/sxmo_bluetoothmenu.sh +4 -0
@@ 1,5 1,9 @@
#!/usr/bin/env sh

# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"

ispaired() {
	bluetoothctl info "$1" | grep Paired | grep -q yes
}

M scripts/core/sxmo_common.sh => scripts/core/sxmo_common.sh +3 -0
@@ 30,6 30,9 @@ command -v "$KEYBOARD" > /dev/null || export KEYBOARD=svkbd-mobile-intl
# shellcheck disable=SC2039
command -v shopt > /dev/null && shopt -s expand_aliases

alias dmenu="sxmo_dmenu.sh"
alias st="sxmo_terminal.sh"

alias find="busybox find"
alias pkill="busybox pkill"
alias pgrep="busybox pgrep"

A scripts/core/sxmo_dmenu.sh => scripts/core/sxmo_dmenu.sh +9 -0
@@ 0,0 1,9 @@
#!/usr/bin/env sh

TERMMODE=$([ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] && echo "true")

if [ "$TERMMODE" != "true" ]; then
	exec dmenu "$@"
else
	exec vis-menu -i -l 10
fi

M scripts/core/sxmo_dmenu_with_kb.sh => scripts/core/sxmo_dmenu_with_kb.sh +5 -0
@@ 1,5 1,10 @@
#!/usr/bin/env sh

TERMMODE=$([ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] && echo "true")
if [ "$TERMMODE" = "true" ]; then
	exec vis-menu -i -l 10
fi

wasopen="$(sxmo_keyboard.sh isopen && echo "yes")"

sxmo_keyboard.sh open

A scripts/core/sxmo_terminal.sh => scripts/core/sxmo_terminal.sh +14 -0
@@ 0,0 1,14 @@
#!/usr/bin/env sh

TERMMODE=$([ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] && echo "true")

if [ "$TERMMODE" = "true" ]; then
	while [ "-e" != "$1" ] || [ 0 -eq $# ]; do
		shift
	done
	shift
else
	set -- st "$@"
fi

exec "$@"

M scripts/modem/sxmo_modemtext.sh => scripts/modem/sxmo_modemtext.sh +6 -21
@@ 4,19 4,9 @@
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"

TERMMODE=$([ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] && echo "true")

menu() {
	if [ "$TERMMODE" != "true" ]; then
		"$@"
	else
		vis-menu -i -l 10
	fi
}

err() {
	echo "$1">&2
	echo "$1" | menu dmenu -c -l 10
	echo "$1" | dmenu -c -l 10
	kill $$
}



@@ 25,7 15,7 @@ choosenumbermenu() {
	NUMBER="$(
		printf %b "\n$icon_cls Cancel\n$icon_grp More contacts\n$(sxmo_contacts.sh | grep -E "^\+?[0-9]+:")" |
		awk NF |
		menu sxmo_dmenu_with_kb.sh -p "Number" -l 10 -c -i |
		sxmo_dmenu_with_kb.sh -p "Number" -l 10 -c -i |
		cut -d: -f1 |
		tr -d -- '- '
	)"


@@ 33,7 23,7 @@ choosenumbermenu() {
		NUMBER="$( #joined words without space is not a bug
			printf %b "\nCancel\n$(sxmo_contacts.sh --all)" |
				grep . |
				menu sxmo_dmenu_with_kb.sh -l 10 -p "Number" -c -i |
				sxmo_dmenu_with_kb.sh -l 10 -p "Number" -c -i |
				cut -d: -f1 |
				tr -d -- '- '
		)"


@@ 71,7 61,7 @@ sendtextmenu() {
	do
		CONFIRM="$(
			printf %b "$icon_edt Edit\n$icon_snd Send\n$icon_cls Cancel" |
			menu dmenu -c -idx 1 -p "Confirm" -l 10
			dmenu -c -idx 1 -p "Confirm" -l 10
		)"
		if echo "$CONFIRM" | grep -q "Send"; then
			(sxmo_modemsendsms.sh "$NUMBER" - < "$DRAFT") && \


@@ 90,12 80,7 @@ tailtextlog() {
	CONTACTNAME="$(sxmo_contacts.sh | grep "^$NUMBER" | cut -d' ' -f2-)"
	[ "Unknown Number" = "$CONTACTNAME" ] && CONTACTNAME="$CONTACTNAME ($NUMBER)"

	set -- sh -c "tail -n9999 -f \"$LOGDIR/$NUMBER/sms.txt\" | sed \"s|$NUMBER|$CONTACTNAME|g\""
	if [ "$TERMMODE" != "true" ]; then
		st -T "$NUMBER SMS" -e "$@"
	else
		"$@"
	fi
	st -T "$NUMBER SMS" -e sh -c "tail -n9999 -f \"$LOGDIR/$NUMBER/sms.txt\" | sed \"s|$NUMBER|$CONTACTNAME|g\""
}

readtextmenu() {


@@ 107,7 92,7 @@ readtextmenu() {
			printf %b "$CONTACT" | xargs -IL echo "L logfile"
		done
	)"
	PICKED="$(printf %b "$ENTRIES" | menu dmenu -p Texts -c -l 10 -i)"
	PICKED="$(printf %b "$ENTRIES" | dmenu -p Texts -c -l 10 -i)"

	if echo "$PICKED" | grep "Close Menu"; then
		exit 1