diff --git a/scripts/core/sxmo_bluetoothmenu.sh b/scripts/core/sxmo_bluetoothmenu.sh index 5820539..c932a89 100755 --- a/scripts/core/sxmo_bluetoothmenu.sh +++ b/scripts/core/sxmo_bluetoothmenu.sh @@ -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 } diff --git a/scripts/core/sxmo_common.sh b/scripts/core/sxmo_common.sh index 5050212..ffd4934 100644 --- a/scripts/core/sxmo_common.sh +++ b/scripts/core/sxmo_common.sh @@ -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" diff --git a/scripts/core/sxmo_dmenu.sh b/scripts/core/sxmo_dmenu.sh new file mode 100755 index 0000000..799485c --- /dev/null +++ b/scripts/core/sxmo_dmenu.sh @@ -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 diff --git a/scripts/core/sxmo_dmenu_with_kb.sh b/scripts/core/sxmo_dmenu_with_kb.sh index b36b4b8..f855b8a 100755 --- a/scripts/core/sxmo_dmenu_with_kb.sh +++ b/scripts/core/sxmo_dmenu_with_kb.sh @@ -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 diff --git a/scripts/core/sxmo_terminal.sh b/scripts/core/sxmo_terminal.sh new file mode 100755 index 0000000..18e2212 --- /dev/null +++ b/scripts/core/sxmo_terminal.sh @@ -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 "$@" diff --git a/scripts/modem/sxmo_modemtext.sh b/scripts/modem/sxmo_modemtext.sh index ec55d7d..6271866 100755 --- a/scripts/modem/sxmo_modemtext.sh +++ b/scripts/modem/sxmo_modemtext.sh @@ -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