Shellcheck and tabindent all scripts

master
Miles Alan 4 years ago
parent bd5ead19e5
commit 049a93e5d8
  1. 4
      README.md
  2. 2
      scripts/appscripts/sxmo_record.sh
  3. 29
      scripts/appscripts/sxmo_rss.sh
  4. 174
      scripts/core/sxmo_appmenu.sh
  5. 6
      scripts/core/sxmo_audiocurrentdevice.sh
  6. 6
      scripts/core/sxmo_audioout.sh
  7. 4
      scripts/core/sxmo_blinkled.sh
  8. 10
      scripts/core/sxmo_brightness.sh
  9. 1
      scripts/core/sxmo_dmenu_with_kb.sh
  10. 2
      scripts/core/sxmo_edit_screen.sh
  11. 4
      scripts/core/sxmo_flashtoggle.sh
  12. 17
      scripts/core/sxmo_pipecomplete.sh
  13. 25
      scripts/core/sxmo_statusbar.sh
  14. 10
      scripts/core/sxmo_surf_linkselect.sh
  15. 8
      scripts/core/sxmo_timezonechange.sh
  16. 2
      scripts/core/sxmo_upgrade.sh
  17. 18
      scripts/core/sxmo_urlhandler.sh
  18. 1
      scripts/core/sxmo_xinit.sh
  19. 41
      scripts/modem/sxmo_modemcall.sh
  20. 47
      scripts/modem/sxmo_modemmonitor.sh
  21. 7
      scripts/modem/sxmo_modemmonitortoggle.sh
  22. 65
      scripts/modem/sxmo_modemtext.sh

@ -1,5 +1,5 @@
# sxmo-utils # sxmo-utils
This repository contains scripts and C programs to support sxmo. This repository contains scripts and C programs to support Sxmo.
Note all scripts pass shellcheck and are tab-idented.

@ -47,7 +47,7 @@ record() {
} }
while true; do while true; do
NRECORDINGS="$(ls -1 "$RECDIR" | wc -l)" NRECORDINGS="$(find "$RECDIR" -type f | wc -l)"
OPTION="$( OPTION="$(
printf %b "Line Jack\nMicrophone\n($NRECORDINGS) Recordings\nClose Menu" | printf %b "Line Jack\nMicrophone\n($NRECORDINGS) Recordings\nClose Menu" |
dmenu -fn Terminus-30 -c -p "Record" -l 20 dmenu -fn Terminus-30 -c -p "Record" -l 20

@ -1,5 +1,16 @@
#!/usr/bin/env sh #!/usr/bin/env sh
if [ -f "$XDG_CONFIG_HOME/sxmo/sfeedrc" ]; then
SFEEDCONF="$XDG_CONFIG_HOME/sxmo/sfeedrc"
elif [ -f "$HOME/.sfeed/sfeedrc" ]; then
SFEEDCONF="$HOME/.sfeed/sfeedrc"
else
SFEEDCONF=/usr/share/sxmo/sxmo_sfeedrc SFEEDCONF=/usr/share/sxmo/sxmo_sfeedrc
fi
die() {
echo "Error: $1"
exit 1
}
tflt() { tflt() {
# Date with feature like "1 day ago" etc main reason # Date with feature like "1 day ago" etc main reason
@ -9,19 +20,19 @@ tflt() {
} }
prep_temp_folder_with_items() { prep_temp_folder_with_items() {
mkdir -p $FOLDER mkdir -p "$FOLDER"
rm -rf $FOLDER/* rm -rf "${FOLDER:?}/*"
cd ~/.sfeed/feeds/ cd ~/.sfeed/feeds/ || die "Could cd to ~/.sfeed/feeds/"
for f in $(ls) for f in ./*; do
do fclean="$(basename "$f")"
cat $f | tflt $@ > $FOLDER/$f tflt < "$fclean" > "$FOLDER/$fclean"
[ -s $FOLDER/$f ] || rm $FOLDER/$f [ -s "$FOLDER/$fclean" ] || rm "${FOLDER:?}/$fclean"
done done
} }
list_items() { list_items() {
cd $FOLDER cd "$FOLDER" || die "Couldn't cd to $FOLDER"
gawk -F'\t' '{print $1 " " FILENAME " | " $2 ": " $3}' * |\ gawk -F'\t' '{print $1 " " substr(FILENAME, 3) " | " $2 ": " $3}' ./* |\
grep -E '^[0-9]{5}' |\ grep -E '^[0-9]{5}' |\
sort -nk1 |\ sort -nk1 |\
sort -r |\ sort -r |\

@ -2,37 +2,20 @@
WIN=$(xdotool getwindowfocus) WIN=$(xdotool getwindowfocus)
programchoicesinit() { programchoicesinit() {
XPROPOUT="$(xprop -id $(xdotool getactivewindow))" XPROPOUT="$(xprop -id "$(xdotool getactivewindow)")"
WMCLASS="${1:-$(echo "$XPROPOUT" | grep WM_CLASS | cut -d ' ' -f3-)}" WMCLASS="${1:-$(echo "$XPROPOUT" | grep WM_CLASS | cut -d ' ' -f3-)}"
# Default system menu (no matches) if echo "$WMCLASS" | grep -i "userscripts"; then
CHOICES="$(echo "
$(
[ -n "$(ls -A $XDG_CONFIG_HOME/sxmo/userscripts)" ] &&
echo 'Userscripts ^ 0 ^ sxmo_appmenu.sh userscripts'
)
Scripts ^ 0 ^ sxmo_appmenu.sh scripts
Apps ^ 0 ^ sxmo_appmenu.sh applications
Volume ↑ ^ 1 ^ sxmo_vol.sh up
Volume ↓ ^ 1 ^ sxmo_vol.sh down
Dialer ^ 0 ^ sxmo_modemcall.sh dial
Texts ^ 0 ^ sxmo_modemtext.sh
Camera ^ 0 ^ sxmo_camera.sh
Wifi ^ 0 ^ st -e "nmtui"
Audio ^ 0 ^ sxmo_appmenu.sh audioout
Config ^ 0 ^ sxmo_appmenu.sh config
Logout ^ 0 ^ pkill -9 dwm
")" && WINNAME=Sys
# Userscripts menu # Userscripts menu
echo $WMCLASS | grep -i "userscripts" && CHOICES="$( CHOICES="$(
ls -1 $XDG_CONFIG_HOME/sxmo/userscripts | find "$XDG_CONFIG_HOME/sxmo/userscripts" -type f -print0 |
sed 's/ /\\ /' | xargs -IF basename F |
awk '{printf "%s\t^ 0 ^ $XDG_CONFIG_HOME/sxmo/userscripts/%s \n", $0, $0}' awk '{printf "%s\t^ 0 ^ $XDG_CONFIG_HOME/sxmo/userscripts/%s \n", $0, $0}'
)" && WINNAME=Userscripts && return )"
WINNAME=Userscripts
elif echo "$WMCLASS" | grep -i "scripts"; then
# Scripts menu # Scripts menu
echo $WMCLASS | grep -i "scripts" && CHOICES="$(echo " CHOICES="
Web Search ^ 0 ^ sxmo_websearch.sh Web Search ^ 0 ^ sxmo_websearch.sh
Files ^ 0 ^ sxmo_files.sh Files ^ 0 ^ sxmo_files.sh
Record ^ 0 ^ sxmo_record.sh Record ^ 0 ^ sxmo_record.sh
@ -41,10 +24,11 @@ programchoicesinit() {
Youtube (Audio) ^ 0 ^ sxmo_youtube.sh audio Youtube (Audio) ^ 0 ^ sxmo_youtube.sh audio
Weather ^ 0 ^ sxmo_weather.sh Weather ^ 0 ^ sxmo_weather.sh
RSS ^ 0 ^ sxmo_rss.sh RSS ^ 0 ^ sxmo_rss.sh
")" && WINNAME=Scripts && return "
WINNAME=Scripts
elif echo "$WMCLASS" | grep -i "applications"; then
# Apps menu # Apps menu
echo $WMCLASS | grep -i "applications" && CHOICES="$(echo " CHOICES="
Surf ^ 0 ^ surf Surf ^ 0 ^ surf
Netsurf ^ 0 ^ netsurf Netsurf ^ 0 ^ netsurf
Firefox ^ 0 ^ firefox Firefox ^ 0 ^ firefox
@ -53,37 +37,40 @@ programchoicesinit() {
Xcalc ^ 0 ^ xcalc Xcalc ^ 0 ^ xcalc
St ^ 0 ^ st St ^ 0 ^ st
Foxtrotgps ^ 0 ^ foxtrotgps Foxtrotgps ^ 0 ^ foxtrotgps
")" && WINNAME=Apps && return "
WINNAME=Apps
elif echo "$WMCLASS" | grep -i "config"; then
# System Control menu # System Control menu
echo $WMCLASS | grep -i "config" && CHOICES="$(echo " CHOICES="
Brightesss ↑ ^ 1 ^ sxmo_brightness.sh up Brightesss ↑ ^ 1 ^ sxmo_brightness.sh up
Brightness ↓ ^ 1 ^ sxmo_brightness.sh down Brightness ↓ ^ 1 ^ sxmo_brightness.sh down
Modem Toggle ^ 1 ^ sxmo_modemmonitortoggle.sh Modem Toggle ^ 1 ^ sxmo_modemmonitortoggle.sh
Modem Info ^ 0 ^ sxmo_modeminfo.sh Modem Info ^ 0 ^ sxmo_modeminfo.sh
Modem Log ^ 0 ^ sxmo_modemlog.sh Modem Log ^ 0 ^ sxmo_modemlog.sh
Flash $( Flash $(
cat /sys/class/leds/white:flash/brightness | grep -qE '^0$' /sys/class/leds/white:flash/brightness &&
grep -E '^0$' > /dev/null && printf %b "Off → On" || printf %b "On → Off";
echo -n "Off → On" || echo -n "On → Off"; printf %b "^ 1 ^ sxmo_flashtoggle.sh"
echo -n "^ 1 ^ sxmo_flashtoggle.sh"
) )
Bar Toggle ^ 1 ^ key Alt+b Bar Toggle ^ 1 ^ key Alt+b
Change Timezone ^ 1 ^ sxmo_timezonechange.sh Change Timezone ^ 1 ^ sxmo_timezonechange.sh
Rotate ^ 1 ^ sxmo_rotate.sh Rotate ^ 1 ^ sxmo_rotate.sh
Upgrade Pkgs ^ 0 ^ st -e sxmo_upgrade.sh Upgrade Pkgs ^ 0 ^ st -e sxmo_upgrade.sh
")" && WINNAME=Config && return "
WINNAME=Config
elif echo "$WMCLASS" | grep -i "audioout"; then
# Audio Out menu # Audio Out menu
echo $WMCLASS | grep -i "audioout" && CURRENTDEV="$(sxmo_audiocurrentdevice.sh)" && CHOICES="$(echo " CURRENTDEV="$(sxmo_audiocurrentdevice.sh)"
Headphones $([[ "$CURRENTDEV" == "Headphone" ]] && echo "✓") ^ 1 ^ sxmo_audioout.sh Headphones CHOICES="
Speaker $([[ "$CURRENTDEV" == "Line Out" ]] && echo "✓") ^ 1 ^ sxmo_audioout.sh Speaker Headphones $([ "$CURRENTDEV" = "Headphone" ] && echo "✓") ^ 1 ^ sxmo_audioout.sh Headphones
Earpiece $([[ "$CURRENTDEV" == "Earpiece" ]] && echo "✓") ^ 1 ^ sxmo_audioout.sh Earpiece Speaker $([ "$CURRENTDEV" = "Line Out" ] && echo "✓") ^ 1 ^ sxmo_audioout.sh Speaker
None $([[ "$CURRENTDEV" == "None" ]] && echo "✓") ^ 1 ^ sxmo_audioout.sh None Earpiece $([ "$CURRENTDEV" = "Earpiece" ] && echo "✓") ^ 1 ^ sxmo_audioout.sh Earpiece
")" && WINNAME="Audio" && return None $([ "$CURRENTDEV" = "None" ] && echo "✓") ^ 1 ^ sxmo_audioout.sh None
"
WINNAME="Audio"
elif echo "$WMCLASS" | grep -i "mpv"; then
# MPV # MPV
echo $WMCLASS | grep -i "mpv" && CHOICES="$(echo " CHOICES="
Pause ^ 0 ^ key space Pause ^ 0 ^ key space
Seek ← ^ 1 ^ key Left Seek ← ^ 1 ^ key Left
Seek → ^ 1 ^ key Right Seek → ^ 1 ^ key Right
@ -95,17 +82,23 @@ programchoicesinit() {
Loopmark ^ 1 ^ key l Loopmark ^ 1 ^ key l
Info ^ 1 ^ key i Info ^ 1 ^ key i
Seek Info ^ 1 ^ key o Seek Info ^ 1 ^ key o
")" && WINNAME=Mpv && return "
WINNAME=Mpv && return
elif echo "$WMCLASS" | grep -i "st-256color"; then
# St # St
echo $WMCLASS | grep -i "st-256color" && STSELMODEON="$(echo "$XPROPOUT" | grep -E '^_ST_SELMODE.+=' | cut -d= -f2 | tr -d ' ')" && CHOICES="$(echo " STSELMODEON="$(
echo "$XPROPOUT" | grep -E '^_ST_SELMODE.+=' | cut -d= -f2 | tr -d ' '
)"
CHOICES="
Type complete ^ 0 ^ key Ctrl+Shift+u Type complete ^ 0 ^ key Ctrl+Shift+u
Copy complete ^ 0 ^ key Ctrl+Shift+i Copy complete ^ 0 ^ key Ctrl+Shift+i
Selmode $( Selmode $(
[ $STSELMODEON == 1 ] && printf %b 'On → Off' || printf %b 'Off → On'; [ "$STSELMODEON" = 1 ] &&
printf %b 'On → Off' ||
printf %b 'Off → On'
printf %b '^ 0 ^ key Ctrl+Shift+s' printf %b '^ 0 ^ key Ctrl+Shift+s'
) )
$([ $STSELMODEON == 1 ] && echo 'Copy selection ^ 0 ^ key Ctrl+Shift+c') $([ "$STSELMODEON" = 1 ] && echo 'Copy selection ^ 0 ^ key Ctrl+Shift+c')
Paste ^ 0 ^ key Ctrl+Shift+v Paste ^ 0 ^ key Ctrl+Shift+v
Zoom + ^ 1 ^ key Ctrl+Shift+Prior Zoom + ^ 1 ^ key Ctrl+Shift+Prior
Zoom - ^ 1 ^ key Ctrl+Shift+Next Zoom - ^ 1 ^ key Ctrl+Shift+Next
@ -113,26 +106,29 @@ programchoicesinit() {
Scroll ↓ ^ 1 ^ key Ctrl+Shift+f Scroll ↓ ^ 1 ^ key Ctrl+Shift+f
Invert ^ 1 ^ key Ctrl+Shift+x Invert ^ 1 ^ key Ctrl+Shift+x
Hotkeys ^ 0 ^ sxmo_appmenu.sh sthotkeys Hotkeys ^ 0 ^ sxmo_appmenu.sh sthotkeys
")" && WINNAME=St && return "
WINNAME=St
elif echo "$WMCLASS" | grep -i "sthotkeys"; then
# St hotkeys # St hotkeys
echo $WMCLASS | grep -i "sthotkeys" && CHOICES="$(echo " CHOICES="
Send Ctrl-C ^ 0 ^ key Ctrl+c Send Ctrl-C ^ 0 ^ key Ctrl+c
Send Ctrl-L ^ 0 ^ key Ctrl+l Send Ctrl-L ^ 0 ^ key Ctrl+l
Send Ctrl-D ^ 0 ^ key Ctrl+d Send Ctrl-D ^ 0 ^ key Ctrl+d
")" && WINNAME=St && return "
WINNAME=St
elif echo "$WMCLASS" | grep -i netsurf; then
# Netsurf # Netsurf
echo $WMCLASS | grep -i netsurf && CHOICES="$(echo " CHOICES="
Pipe URL ^ 0 ^ sxmo_urlhandler.sh Pipe URL ^ 0 ^ sxmo_urlhandler.sh
Zoom + ^ 1 ^ key Ctrl+plus Zoom + ^ 1 ^ key Ctrl+plus
Zoom - ^ 1 ^ key Ctrl+minus Zoom - ^ 1 ^ key Ctrl+minus
History ← ^ 1 ^ key Alt+Left History ← ^ 1 ^ key Alt+Left
History → ^ 1 ^ key Alt+Right History → ^ 1 ^ key Alt+Right
")" && WINNAME=Netsurf && return "
WINNAME=Netsurf
elif echo "$WMCLASS" | grep surf; then
# Surf # Surf
echo $WMCLASS | grep surf && CHOICES="$(echo " CHOICES="
Navigate ^ 0 ^ key Ctrl+g Navigate ^ 0 ^ key Ctrl+g
Link Menu ^ 0 ^ key Ctrl+d Link Menu ^ 0 ^ key Ctrl+d
Pipe URL ^ 0 ^ sxmo_urlhandler.sh Pipe URL ^ 0 ^ sxmo_urlhandler.sh
@ -143,37 +139,61 @@ programchoicesinit() {
JS Toggle ^ 1 ^ key Ctrl+Shift+s JS Toggle ^ 1 ^ key Ctrl+Shift+s
History ← ^ 1 ^ key Ctrl+h History ← ^ 1 ^ key Ctrl+h
History → ^ 1 ^ key Ctrl+l History → ^ 1 ^ key Ctrl+l
")" && WINNAME=Surf && return "
WINNAME=Surf
elif echo "$WMCLASS" | grep -i firefox; then
# Firefox # Firefox
echo $WMCLASS | grep -i firefox && CHOICES="$(echo " CHOICES="
Pipe URL ^ 0 ^ sxmo_urlhandler.sh Pipe URL ^ 0 ^ sxmo_urlhandler.sh
Zoom + ^ 1 ^ key Ctrl+plus Zoom + ^ 1 ^ key Ctrl+plus
Zoom - ^ 1 ^ key Ctrl+minus Zoom - ^ 1 ^ key Ctrl+minus
History ← ^ 1 ^ key Alt+Left History ← ^ 1 ^ key Alt+Left
History → ^ 1 ^ key Alt+Right History → ^ 1 ^ key Alt+Right
")" && WINNAME=Firefox && return "
WINNAME=Firefox
elif echo "$WMCLASS" | grep -i foxtrot; then
# Foxtrot GPS # Foxtrot GPS
echo $WMCLASS | grep -i foxtrot && CHOICES="$(echo " CHOICES="
Zoom + ^ 1 ^ key i Zoom + ^ 1 ^ key i
Zoom - ^ 1 ^ key o Zoom - ^ 1 ^ key o
Panel toggle ^ 1 ^ key m Panel toggle ^ 1 ^ key m
Autocenter toggle ^ 0 ^ key a Autocenter toggle ^ 0 ^ key a
Route ^ 0 ^ key r Route ^ 0 ^ key r
")" && WINNAME=Gps && return "
WINNAME=Gps
else
# Default system menu (no matches)
CHOICES="
$(
[ -n "$(ls -A "$XDG_CONFIG_HOME"/sxmo/userscripts)" ] &&
echo 'Userscripts ^ 0 ^ sxmo_appmenu.sh userscripts'
)
Scripts ^ 0 ^ sxmo_appmenu.sh scripts
Apps ^ 0 ^ sxmo_appmenu.sh applications
Volume ↑ ^ 1 ^ sxmo_vol.sh up
Volume ↓ ^ 1 ^ sxmo_vol.sh down
Dialer ^ 0 ^ sxmo_modemcall.sh dial
Texts ^ 0 ^ sxmo_modemtext.sh
Camera ^ 0 ^ sxmo_camera.sh
Wifi ^ 0 ^ st -e nmtui
Audio ^ 0 ^ sxmo_appmenu.sh audioout
Config ^ 0 ^ sxmo_appmenu.sh config
Logout ^ 0 ^ pkill -9 dwm
"
WINNAME=Sys
fi
} }
getprogchoices() { getprogchoices() {
# E.g. sets CHOICES var # E.g. sets CHOICES var
programchoicesinit $@ programchoicesinit "$@"
# Decorate menu at top w/ incoming call entry if present # Decorate menu at top w/ incoming call entry if present
INCOMINGCALL=$(cat /tmp/sxmo_incomingcall || echo NOCALL) INCOMINGCALL="$(cat /tmp/sxmo_incomingcall || echo NOCALL)"
echo "$INCOMINGCALL" | grep -v NOCALL && CHOICES="$(echo " echo "$INCOMINGCALL" | grep -v NOCALL && CHOICES="
Pickup $(echo $INCOMINGCALL | cut -d: -f2) ^ 0 ^ sxmo_modemcall.sh pickup $(echo $INCOMINGCALL | cut -d: -f1) Pickup $(echo "$INCOMINGCALL" | cut -d: -f2) ^ 0 ^ sxmo_modemcall.sh pickup $(echo "$INCOMINGCALL" | cut -d: -f1)
$CHOICES $CHOICES
")" "
# Decorate menu at bottom w/ system menu entry if not system menu # Decorate menu at bottom w/ system menu entry if not system menu
echo $WINNAME | grep -v Sys && CHOICES=" echo $WINNAME | grep -v Sys && CHOICES="
@ -203,12 +223,12 @@ quit() {
mainloop() { mainloop() {
DMENUIDX=0 DMENUIDX=0
PICKED="" PICKED=""
ARGS="$@" ARGS="$*"
while : while :
do do
# E.g. sets PROGCHOICES # E.g. sets PROGCHOICES
getprogchoices $ARGS getprogchoices "$ARGS"
PICKED="$( PICKED="$(
echo "$PROGCHOICES" | echo "$PROGCHOICES" |
@ -219,11 +239,11 @@ mainloop() {
CMD="$(echo "$PROGCHOICES" | grep -F "$PICKED" | cut -d '^' -f3)" CMD="$(echo "$PROGCHOICES" | grep -F "$PICKED" | cut -d '^' -f3)"
DMENUIDX="$(echo "$PROGCHOICES" | grep -F -n "$PICKED" | cut -d ':' -f1)" DMENUIDX="$(echo "$PROGCHOICES" | grep -F -n "$PICKED" | cut -d ':' -f1)"
echo "Eval: <$CMD> from picked <$PICKED> with loop <$LOOP>" echo "Eval: <$CMD> from picked <$PICKED> with loop <$LOOP>"
eval $CMD eval "$CMD"
echo $LOOP | grep 1 || quit echo "$LOOP" | grep 1 || quit
done done
} }
pgrep -f sxmo_appmenu.sh | grep -Ev "^${$}$" | xargs kill -9 pgrep -f sxmo_appmenu.sh | grep -Ev "^${$}$" | xargs kill -9
pkill -9 dmenu pkill -9 dmenu
mainloop $@ mainloop "$@"

@ -1,8 +1,8 @@
#!/usr/bin/env sh #!/usr/bin/env sh
audiodevice() { audiodevice() {
amixer sget "Earpiece" | grep -E '\[on\]' > /dev/null && echo Earpiece && return amixer sget "Earpiece" | grep -qE '\[on\]' && echo Earpiece && return
amixer sget "Headphone" | grep -E '\[on\]' > /dev/null && echo Headphone && return amixer sget "Headphone" | grep -qE '\[on\]' && echo Headphone && return
amixer sget "Line Out" | grep -E '\[on\]' > /dev/null && echo Line Out && return amixer sget "Line Out" | grep -qE '\[on\]' && echo Line Out && return
echo "None" echo "None"
} }

@ -9,11 +9,11 @@ amixer set "$SPEAKER" mute
amixer set "$HEADPHONE" mute amixer set "$HEADPHONE" mute
amixer set "$EARPIECE" mute amixer set "$EARPIECE" mute
if [[ "$ARG" = "Speaker" ]]; then if [ "$ARG" = "Speaker" ]; then
amixer set "$SPEAKER" unmute amixer set "$SPEAKER" unmute
elif [[ "$ARG" = "Headphones" ]]; then elif [ "$ARG" = "Headphones" ]; then
amixer set "$HEADPHONE" unmute amixer set "$HEADPHONE" unmute
elif [[ "$ARG" = "Earpiece" ]]; then elif [ "$ARG" = "Earpiece" ]; then
amixer set "$EARPIECE" unmute amixer set "$EARPIECE" unmute
fi fi

@ -1,4 +1,4 @@
#!/usr/bin/env sh #!/usr/bin/env sh
sxmo_setpineled $1 150 sxmo_setpineled "$1" 150
sleep 0.01 sleep 0.01
sxmo_setpineled $1 0 sxmo_setpineled "$1" 0

@ -8,24 +8,22 @@ MINSTEP=1
STEP=$(echo "($MAX - $MIN) / 10" | bc | xargs -ISTP echo -e "$MINSTEP\nSTP" | sort -r | head -n1) STEP=$(echo "($MAX - $MIN) / 10" | bc | xargs -ISTP echo -e "$MINSTEP\nSTP" | sort -r | head -n1)
setdelta() { setdelta() {
sxmo_setpinebacklight $( sxmo_setpinebacklight "$(
cat $DEV/brightness | xargs -IB echo B "$1" < $DEV/brightness |
xargs -IB echo B $1 |
bc | bc |
xargs -INUM echo -e "$MIN\nNUM" | sort -n | tail -n1 | xargs -INUM echo -e "$MIN\nNUM" | sort -n | tail -n1 |
xargs -INUM echo -e "$MAX\nNUM" | sort -n | head -n1 xargs -INUM echo -e "$MAX\nNUM" | sort -n | head -n1
) )"
dunstify -i 0 -u normal -r 999 "$(cat $DEV/brightness)/${MAX}" dunstify -i 0 -u normal -r 999 "$(cat $DEV/brightness)/${MAX}"
} }
up() { up() {
setdelta "+${STEP}" setdelta "+${STEP}"
} }
down() { down() {
setdelta "-${STEP}" setdelta "-${STEP}"
} }
$1 $2 "$1" "$2"

@ -1,6 +1,7 @@
#!/usr/bin/env sh #!/usr/bin/env sh
pidof svkbd-sxmo >&2 || svkbd-sxmo & pidof svkbd-sxmo >&2 || svkbd-sxmo &
# shellcheck disable=SC2068
OUTPUT="$(cat | dmenu $@)" OUTPUT="$(cat | dmenu $@)"
pkill svkbd-sxmo >&2 pkill svkbd-sxmo >&2
echo "$OUTPUT" echo "$OUTPUT"

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env sh
tmpfile=$(mktemp /tmp/st-edit.XXXXXX) tmpfile=$(mktemp /tmp/st-edit.XXXXXX)
trap 'rm "$tmpfile"' 0 1 15 trap 'rm "$tmpfile"' 0 1 15
cat > "$tmpfile" cat > "$tmpfile"

@ -1,6 +1,6 @@
#!/usr/bin/env sh #!/usr/bin/env sh
sxmo_setpineled white "$( sxmo_setpineled white "$(
cat /sys/class/leds/white:flash/brightness | grep -qE '^0$' /sys/class/leds/white:flash/brightness &&
grep -E '^0$' > /dev/null && echo 255 || echo 0 echo 255 || echo 0
)" )"

@ -5,10 +5,13 @@ STWIN="$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')"
menu() { menu() {
pidof svkbd-sxmo || svkbd-sxmo & pidof svkbd-sxmo || svkbd-sxmo &
RESULT="$( RESULT="$(
echo "$(
echo "Close Menu" && echo "Close Menu" &&
echo "$INPUT" | grep -Eo '\S+' | tr -d '[:blank:]' | sort | uniq echo "$INPUT" |
)" | dmenu -p "$PROMPT" -l 10 -i -c -fn Terminus-20 grep -Eo '\S+' |
tr -d '[:blank:]' |
sort |
uniq |
dmenu -p "$PROMPT" -l 10 -i -c -fn Terminus-20
)" )"
pkill svkbd-sxmo pkill svkbd-sxmo
} }
@ -16,7 +19,7 @@ menu() {
copy() { copy() {
PROMPT=Copy PROMPT=Copy
menu menu
if [[ "$RESULT" = "Close Menu" ]]; then if [ "$RESULT" = "Close Menu" ]; then
exit 0 exit 0
else else
echo "$RESULT" | xclip -i echo "$RESULT" | xclip -i
@ -26,11 +29,11 @@ copy() {
type() { type() {
PROMPT=Type PROMPT=Type
menu menu
if [[ "$RESULT" = "Close Menu" ]]; then if [ "$RESULT" = "Close Menu" ]; then
exit 0 exit 0
else else
xdotool type --window $STWIN "$RESULT" xdotool type --window "$STWIN" "$RESULT"
fi fi
} }
$@ "$1"

@ -2,7 +2,7 @@
pgrep -f sxmo_statusbar.sh | grep -v $$ | xargs kill -9 pgrep -f sxmo_statusbar.sh | grep -v $$ | xargs kill -9
UPDATEFILE=/tmp/sxmo_bar UPDATEFILE=/tmp/sxmo_bar
touch $UPDATEFILE touch "$UPDATEFILE"
update() { update() {
# M symbol if modem monitoring is on & modem present # M symbol if modem monitoring is on & modem present
@ -10,15 +10,15 @@ update() {
pgrep -f sxmo_modemmonitor.sh && MODEMMON="M " pgrep -f sxmo_modemmonitor.sh && MODEMMON="M "
# Battery pct # Battery pct
PCT=$(cat /sys/class/power_supply/*-battery/capacity) PCT="$(cat /sys/class/power_supply/*-battery/capacity)"
BATSTATUS=$( BATSTATUS="$(
cat /sys/class/power_supply/*-battery/status | cat /sys/class/power_supply/*-battery/status |
cut -c1 cut -c1
) )"
# Volume # Volume
AUDIODEV="$(sxmo_audiocurrentdevice.sh)" AUDIODEV="$(sxmo_audiocurrentdevice.sh)"
[[ $AUDIODEV == "None" ]] && VOL="" || VOL=$(echo "$AUDIODEV" | cut -c1 | tr L S)"$( [ "$AUDIODEV" = "None" ] && VOL="" || VOL=$(echo "$AUDIODEV" | cut -c1 | tr L S)"$(
amixer sget "$AUDIODEV" | amixer sget "$AUDIODEV" |
grep -oE '([0-9]+)%' | grep -oE '([0-9]+)%' |
tr -d ' %' | tr -d ' %' |
@ -27,7 +27,7 @@ update() {
)" )"
# Time # Time
TIME=$(date +%R) TIME="$(date +%R)"
BAR=" ${MODEMMON}${VOL} ${BATSTATUS}${PCT}% ${TIME}" BAR=" ${MODEMMON}${VOL} ${BATSTATUS}${PCT}% ${TIME}"
xsetroot -name "$BAR" xsetroot -name "$BAR"
@ -36,9 +36,18 @@ update() {
# E.g. on first boot justs to make sure the bar comes in quickly # E.g. on first boot justs to make sure the bar comes in quickly
update && sleep 1 && update && sleep 1 && update update && sleep 1 && update && sleep 1 && update
periodicupdate() {
while :
do
echo 1 > "$UPDATEFILE"
sleep 30
done
}
periodicupdate &
while : while :
do do
update update
inotifywait -e MODIFY $UPDATEFILE & sleep 30 & wait -n inotifywait -e MODIFY "$UPDATEFILE"
pgrep -P $$ | xargs kill -9
done done

@ -10,7 +10,7 @@
SURF_WINDOW="${1:-$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')}" SURF_WINDOW="${1:-$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')}"
DMENU_PROMPT="${2:-Link}" DMENU_PROMPT="${2:-Link}"
function dump_links_with_titles() { dump_links_with_titles() {
awk '{ awk '{
input = $0; input = $0;
@ -37,9 +37,9 @@ function dump_links_with_titles() {
}' }'
} }
function link_normalize() { link_normalize() {
URI=$1 URI=$1
awk -v uri=$URI '{ awk -v uri="$URI" '{
gsub("&amp;", "\\&"); gsub("&amp;", "\\&");
if ($0 ~ /^https?:\/\// || $0 ~ /^\/\/.+$/) { if ($0 ~ /^https?:\/\// || $0 ~ /^\/\/.+$/) {
@ -62,7 +62,7 @@ function link_normalize() {
}' }'
} }
function link_select() { link_select() {
tr '\n\r' ' ' | tr '\n\r' ' ' |
xmllint --html --xpath "//a" - | xmllint --html --xpath "//a" - |
dump_links_with_titles | dump_links_with_titles |
@ -70,7 +70,7 @@ function link_select() {
# sort | uniq # sort | uniq
dmenu -p "$DMENU_PROMPT" -l 10 -i -c | dmenu -p "$DMENU_PROMPT" -l 10 -i -c |
awk -F' ' '{print $NF}' | awk -F' ' '{print $NF}' |
link_normalize $(xprop -id $SURF_WINDOW _SURF_URI | cut -d '"' -f 2) link_normalize "$(xprop -id "$SURF_WINDOW" _SURF_URI | cut -d '"' -f 2)"
} }
pidof svkbd-sxmo || svkbd-sxmo & pidof svkbd-sxmo || svkbd-sxmo &

@ -5,7 +5,7 @@ change() {
sudo setup-timezone -z "$1" sudo setup-timezone -z "$1"
echo 1 > /tmp/sxmo_bar echo 1 > /tmp/sxmo_bar
echo Timezone changed ok echo Timezone changed ok
read read -r
} }
menu() { menu() {
@ -18,4 +18,8 @@ menu() {
st -e "$0" change "$T" st -e "$0" change "$T"
} }
[ $# -gt 0 ] && $@ || menu if [ $# -gt 0 ]; then
"$1" "$2"
else
menu
fi

@ -6,4 +6,4 @@ echo "Upgrading all packages"
sudo apk upgrade sudo apk upgrade
echo "Upgrade complete - reboot for all change to take effect" echo "Upgrade complete - reboot for all change to take effect"
read read -r

@ -1,22 +1,20 @@
#!/usr/bin/env sh #!/usr/bin/env sh
if [[ ! -z "$1" ]] if [ -n "$1" ]
then then
# E.g. passed liked: sxmo_urlhandler.sh http://foo.com # E.g. passed liked: sxmo_urlhandler.sh http://foo.com
URL=$1 URL="$1"
else else
# Surf # Surf
WINDOW="$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')" WINDOW="$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')"
SURFURL=`xprop -id $WINDOW | grep URI | awk '{print $3}' | sed 's/\"//g'` SURFURL="$(xprop -id "$WINDOW" | grep URI | awk '{print $3}' | sed 's/\"//g')"
if [[ ! -z "$SURFURL" ]] if [ -n "$SURFURL" ]; then
then
URL="$SURFURL" URL="$SURFURL"
fi fi
# Is normal browser? (FF or Netsurf) - use Ctrl-L Ctrl-C to copy URL # Is normal browser? (FF or Netsurf) - use Ctrl-L Ctrl-C to copy URL
ISNORMBROWS=`xprop -id $(xdotool getactivewindow) | grep -E 'WM_CLASS.*(Netsurf|Firefox)'` ISNORMBROWS="$(xprop -id "$(xdotool getactivewindow)" | grep -E 'WM_CLASS.*(Netsurf|Firefox)')"
if [[ ! -z "$ISNORMBROWS" ]] if [ -n "$ISNORMBROWS" ]; then
then
xdotool key --clearmodifiers --delay 20 "ctrl+l" "ctrl+c" xdotool key --clearmodifiers --delay 20 "ctrl+l" "ctrl+c"
sleep 0.2 sleep 0.2
URL="$(xclip -o)" URL="$(xclip -o)"
@ -39,7 +37,7 @@ COMMAND=$(
aria2c URL aria2c URL
" | sed "s/URL/'URL'/g" | sed -e '/^\s*$/d' | sed -e 's/^\s*//' | dmenu -fn Terminus-15 -p "Pipe URL" -c -l 20 " | sed "s/URL/'URL'/g" | sed -e '/^\s*$/d' | sed -e 's/^\s*//' | dmenu -fn Terminus-15 -p "Pipe URL" -c -l 20
) )
[[ -z "$COMMAND" ]] && exit 1 [ -z "$COMMAND" ] && exit 1
RUN=$(echo $URL | xargs -IURL echo "$COMMAND") RUN=$(echo "$URL" | xargs -IURL echo "$COMMAND")
st -e sh -c "$RUN" st -e sh -c "$RUN"

@ -1,5 +1,6 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# Env vars # Env vars
# shellcheck disable=SC1091
. /etc/profile . /etc/profile
which "$TERM" || export TERM=st which "$TERM" || export TERM=st
which "$BROWSER" || export BROWSER=surf which "$BROWSER" || export BROWSER=surf

@ -21,9 +21,11 @@ contacts() {
} }
modem_cmd_errcheck() { modem_cmd_errcheck() {
ARGS="$@" # shellcheck disable=SC2068
RES="$(mmcli $ARGS 2>&1)" RES="$(mmcli $@ 2>&1)"
[ $? -eq 0 ] || err "Problem executing mmcli command!\n$RES" OK="$?"
echo "Command: mmcli $*"
if [ "$OK" != 0 ]; then err "Problem executing mmcli command!\n$RES"; fi
echo "$RES" echo "$RES"
} }
@ -43,7 +45,7 @@ log_event() {
toggleflag() { toggleflag() {
TOGGLEFLAG=$1 TOGGLEFLAG=$1
shift shift
FLAGS="$@" FLAGS="$*"
echo -- "$FLAGS" | grep -- "$TOGGLEFLAG" >&2 && echo -- "$FLAGS" | grep -- "$TOGGLEFLAG" >&2 &&
NEWFLAGS="$(echo -- "$FLAGS" | sed "s/$TOGGLEFLAG//g")" || NEWFLAGS="$(echo -- "$FLAGS" | sed "s/$TOGGLEFLAG//g")" ||
@ -51,6 +53,7 @@ toggleflag() {
NEWFLAGS="$(echo -- "$NEWFLAGS" | sed "s/--//g; s/ / /g")" NEWFLAGS="$(echo -- "$NEWFLAGS" | sed "s/--//g; s/ / /g")"
# shellcheck disable=SC2086
sxmo_megiaudioroute $NEWFLAGS sxmo_megiaudioroute $NEWFLAGS
echo -- "$NEWFLAGS" echo -- "$NEWFLAGS"
} }
@ -79,7 +82,7 @@ dialmenu() {
grep -oE "[0-9]+" grep -oE "[0-9]+"
)" )"
echo "Starting call with VID: $VID" >&2 echo "Starting call with VID: $VID" >&2
startcall "$VID" >&@ startcall "$VID" >&2
echo "$VID" echo "$VID"
} }
@ -120,17 +123,16 @@ incallmenu() {
toggleflagset "-2" toggleflagset "-2"
toggleflagset "-2" toggleflagset "-2"
while true while true; do
do
CHOICES=" CHOICES="
Volume ↑ ^ sxmo_vol.sh up Volume ↑ ^ sxmo_vol.sh up
Volume ↓ ^ sxmo_vol.sh down Volume ↓ ^ sxmo_vol.sh down
Mic $(echo -- $FLAGS | grep -q -- -m && echo) ^ toggleflagset -m Mic $(echo -- "$FLAGS" | grep -q -- -m && echo) ^ toggleflagset -m
Linemic $(echo -- $FLAGS | grep -q -- -l && echo) ^ toggleflagset -l Linemic $(echo -- "$FLAGS" | grep -q -- -l && echo) ^ toggleflagset -l
Echomic $(echo -- $FLAGS | grep -q -- -z && echo) ^ toggleflagset -z Echomic $(echo -- "$FLAGS" | grep -q -- -z && echo) ^ toggleflagset -z
Earpiece $(echo -- $FLAGS | grep -q -- -e && echo) ^ toggleflagset -e Earpiece $(echo -- "$FLAGS" | grep -q -- -e && echo) ^ toggleflagset -e
Linejack $(echo -- $FLAGS | grep -q -- -h && echo) ^ toggleflagset -h Linejack $(echo -- "$FLAGS" | grep -q -- -h && echo) ^ toggleflagset -h
Speakerphone $(echo -- $FLAGS | grep -q -- -s && echo) ^ toggleflagset -s Speakerphone $(echo -- "$FLAGS" | grep -q -- -s && echo) ^ toggleflagset -s
DTMF Tones ^ dtmfmenu $VID DTMF Tones ^ dtmfmenu $VID
Hangup ^ hangup $VID Hangup ^ hangup $VID
Lock Screen ^ sh -c 'pkill -9 lisgd; sxmo_screenlock; lisgd &' Lock Screen ^ sh -c 'pkill -9 lisgd; sxmo_screenlock; lisgd &'
@ -150,8 +152,8 @@ incallmenu() {
echo "$PICKED" | grep -Ev "." && err "$NUMBER hung up the call" echo "$PICKED" | grep -Ev "." && err "$NUMBER hung up the call"
CMD=$(echo "$CHOICES" | grep "$PICKED" | cut -d '^' -f2) CMD=$(echo "$CHOICES" | grep "$PICKED" | cut -d '^' -f2)
DMENUIDX=$(echo $(echo "$CHOICES" | grep -n "$PICKED" | cut -d ':' -f1) - 1 | bc) DMENUIDX=$(echo "$(echo "$CHOICES" | grep -n "$PICKED" | cut -d ':' -f1)" - 1 | bc)
eval $CMD eval "$CMD"
done done
} }
@ -160,8 +162,7 @@ dtmfmenu() {
DTMFINDEX=0 DTMFINDEX=0
NUMS="0123456789*#ABCD" NUMS="0123456789*#ABCD"
while true while true; do
do
PICKED="$( PICKED="$(
echo "$NUMS" | grep -o . | sed '1 iReturn to Call Menu' | echo "$NUMS" | grep -o . | sed '1 iReturn to Call Menu' |
dmenu -l 20 -fn Terminus-20 -c -idx $DTMFINDEX -p "DTMF Tone" dmenu -l 20 -fn Terminus-20 -c -idx $DTMFINDEX -p "DTMF Tone"
@ -178,9 +179,9 @@ dial() {
} }
pickup() { pickup() {
acceptcall $1 acceptcall "$1"
incallmenu $1 incallmenu "$1"
} }
modem_n || err "Couldn't determine modem number - is modem online?" modem_n || err "Couldn't determine modem number - is modem online?"
$@ "$1" "$2"

@ -2,10 +2,10 @@
TIMEOUT=3 TIMEOUT=3
LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem
ACTIVECALL="NONE" ACTIVECALL="NONE"
trap "kill 0" SIGINT trap "kill 0" INT
err() { err() {
echo -e "$1" | dmenu -fn Terminus-20 -c -l 10 printf %b "$1" | dmenu -fn Terminus-20 -c -l 10
kill -9 0 kill -9 0
} }
@ -21,13 +21,13 @@ newcall() {
sxmo_setpineled green 1 sxmo_setpineled green 1
# Delete all terminated calls # Delete all terminated calls
for i in $(mmcli -m $(modem_n) --voice-list-calls | grep terminated | grep -oE Call\/[0-9]+ | cut -d'/' -f2); do for i in $(mmcli -m "$(modem_n)" --voice-list-calls | grep terminated | grep -oE "Call\/[0-9]+" | cut -d'/' -f2); do
mmcli -m $(modem_n) --voice-delete-call $i mmcli -m "$(modem_n)" --voice-delete-call "$i"
done done
echo "Incoming Call:" echo "Incoming Call:"
INCOMINGNUMBER=$( INCOMINGNUMBER=$(
mmcli -m $(modem_n) --voice-list-calls -o "$VID" -K | mmcli -m "$(modem_n)" --voice-list-calls -o "$VID" -K |
grep call.properties.number | grep call.properties.number |
cut -d ':' -f 2 | cut -d ':' -f 2 |
sed 's/^[+]//' | sed 's/^[+]//' |
@ -35,8 +35,8 @@ newcall() {
) )
TIME="$(date --iso-8601=seconds)" TIME="$(date --iso-8601=seconds)"
mkdir -p $LOGDIR mkdir -p "$LOGDIR"
echo -ne "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> $LOGDIR/modemlog.tsv printf %b "$TIME\tcall_ring\t$INCOMINGNUMBER\n" >> "$LOGDIR/modemlog.tsv"
echo "$VID:$INCOMINGNUMBER" > /tmp/sxmo_incomingcall echo "$VID:$INCOMINGNUMBER" > /tmp/sxmo_incomingcall
echo "Number: $INCOMINGNUMBER (VID: $VID)" echo "Number: $INCOMINGNUMBER (VID: $VID)"
@ -46,8 +46,8 @@ newtexts() {
sxmo_setpineled green 1 sxmo_setpineled green 1
echo "New Texts:" echo "New Texts:"
for i in $(echo -e "$1") ; do for i in $(printf %b "$1") ; do
DAT="$(mmcli -m $(modem_n) -s $i -K)" DAT="$(mmcli -m "$(modem_n)" -s "$i" -K)"
TEXT="$(echo "$DAT" | grep sms.content.text | sed -E 's/^sms\.content\.text\s+:\s+//')" TEXT="$(echo "$DAT" | grep sms.content.text | sed -E 's/^sms\.content\.text\s+:\s+//')"
NUM="$( NUM="$(
@ -58,12 +58,12 @@ newtexts() {
sed 's/^1//' sed 's/^1//'
)" )"
TIME="$(echo "$DAT" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')" TIME="$(echo "$DAT" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')"
TEXTSIZE="$(echo $TEXT | wc -c)" TEXTSIZE="${#TEXT}"
mkdir -p "$LOGDIR/$NUM" mkdir -p "$LOGDIR/$NUM"
echo -ne "Received from $NUM at $TIME:\n$TEXT\n\n" >> $LOGDIR/$NUM/sms.txt printf %b "Received from $NUM at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUM/sms.txt"
echo -ne "$TIME\trecv_txt\t$NUM\t$TEXTSIZE chars\n" >> $LOGDIR/modemlog.tsv printf %b "$TIME\trecv_txt\t$NUM\t$TEXTSIZE chars\n" >> "$LOGDIR/modemlog.tsv"
mmcli -m $(modem_n) --messaging-delete-sms=$i mmcli -m "$(modem_n)" --messaging-delete-sms="$i"
sxmo_vibratepine 300 && sleep 0.1 sxmo_vibratepine 300 && sleep 0.1
sxmo_vibratepine 300 && sleep 0.1 sxmo_vibratepine 300 && sleep 0.1
@ -78,16 +78,15 @@ killinprogresscall() {
inprogresscallchecker() { inprogresscallchecker() {
# E.g. register current call in progress as ACTIVECALL # E.g. register current call in progress as ACTIVECALL
CURRENTCALLS="$(mmcli -m $(modem_n) --voice-list-calls)" CURRENTCALLS="$(mmcli -m "$(modem_n)" --voice-list-calls)"
# E.g. if we've previously registered an ACTIVECALL, check if it # E.g. if we've previously registered an ACTIVECALL, check if it
# was terminated by the otherside, if so kill the incall script # was terminated by the otherside, if so kill the incall script
# and notify user # and notify user
echo "$ACTIVECALL" | grep -E '[0-9]+' && $( if echo "$ACTIVECALL" | grep -E '[0-9]+'; then
echo "$CURRENTCALLS" | echo "$CURRENTCALLS" | grep -E "Call/${ACTIVECALL}.+terminated" &&
grep -E "Call/${ACTIVECALL}.+terminated" &&
killinprogresscall killinprogresscall
) fi
# Register the active call so we can check in future loops if # Register the active call so we can check in future loops if
# other side hung up # other side hung up
@ -104,13 +103,13 @@ while true
do do
sxmo_setpineled green 0 sxmo_setpineled green 0
VOICECALLID="$( VOICECALLID="$(
mmcli -m $(modem_n) --voice-list-calls -a | mmcli -m "$(modem_n)" --voice-list-calls -a |
grep -Eo '[0-9]+ incoming \(ringing-in\)' | grep -Eo '[0-9]+ incoming \(ringing-in\)' |
grep -Eo '[0-9]+' grep -Eo '[0-9]+'
)" )"
TEXTIDS="$( TEXTIDS="$(
mmcli -m $(modem_n) --messaging-list-sms | mmcli -m "$(modem_n)" --messaging-list-sms |
grep -Eo '/SMS/[0-9]+ \(received\)' | grep -Eo '/SMS/[0-9]+ \(received\)' |
grep -Eo '[0-9]+' grep -Eo '[0-9]+'
)" )"
@ -119,7 +118,13 @@ do
inprogresscallchecker inprogresscallchecker
echo "$VOICECALLID" | grep . && newcall "$VOICECALLID" || rm -f /tmp/sxmo_incomingcall if echo "$VOICECALLID" | grep .; then
newcall "$VOICECALLID"
else
rm -f /tmp/sxmo_incomingcall
fi
echo "$TEXTIDS" | grep . && newtexts "$TEXTIDS" echo "$TEXTIDS" | grep . && newtexts "$TEXTIDS"
sleep $TIMEOUT sleep $TIMEOUT
done done

@ -1,5 +1,10 @@
#!/usr/bin/env sh #!/usr/bin/env sh
pgrep -f sxmo_modemmonitor.sh && pkill -9 -f sxmo_modemmonitor.sh || sxmo_modemmonitor.sh & if pgrep -f sxmo_modemmonitor.sh; then
pkill -9 -f sxmo_modemmonitor.sh
else
sxmo_modemmonitor.sh &
fi
rm /tmp/sxmo_incomingcall rm /tmp/sxmo_incomingcall
# E.g. wait until process killed or started -- maybe there's a better way.. # E.g. wait until process killed or started -- maybe there's a better way..

@ -3,47 +3,47 @@ EDITOR=vis
LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem
err() { err() {
echo $1 | dmenu -fn Terminus-20 -c -l 10 echo "$1" | dmenu -fn Terminus-20 -c -l 10
kill $$ kill $$
} }
modem_n() { modem_n() {
MODEMS="$(mmcli -L)" MODEMS="$(mmcli -L)"
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' > /dev/null || err "Couldn't find modem - is your modem enabled?" echo "$MODEMS" | grep -qoE 'Modem\/([0-9]+)' || err "Couldn't find modem - is your modem enabled?"
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2
} }
textcontacts() { textcontacts() {
# TODO: is find automatically sorted by timestamp? # TODO: is find automatically sorted by timestamp?
find $LOGDIR/* -type d -maxdepth 1 | awk -F'/' '{print $NF}' | tac find "$LOGDIR"/* -type d -maxdepth 1 | awk -F'/' '{print $NF}' | tac
} }
editmsg() { editmsg() {
TMP="$(mktemp --suffix $1_msg)" TMP="$(mktemp --suffix "$1_msg")"
echo "$2" > "$TMP" echo "$2" > "$TMP"
TEXT="$(st -e $EDITOR $TMP)" TEXT="$(st -e $EDITOR "$TMP")"
cat $TMP cat "$TMP"
} }
sendmsg() { sendmsg() {
MODEM=$(modem_n) MODEM="$(modem_n)"
NUMBER="$(echo "$1" | sed 's/^[+]//' | sed 's/^1//')" NUMBER="$(echo "$1" | sed 's/^[+]//' | sed 's/^1//')"
TEXT="$2" TEXT="$2"
TEXTSIZE="$(echo "$TEXT" | wc -c)" TEXTSIZE="${#TEXT}"
SMSNO=$( SMSNO="$(
mmcli -m $MODEM --messaging-create-sms="text='$TEXT',number=$NUMBER" | mmcli -m "$MODEM" --messaging-create-sms="text='$TEXT',number=$NUMBER" |
grep -o [0-9]*$ grep -o "[0-9]*$"
) )"
mmcli -s ${SMSNO} --send || err "Couldn't send text message" mmcli -s "${SMSNO}" --send || err "Couldn't send text message"
for i in $(mmcli -m $MODEM --messaging-list-sms | grep " (sent)" | cut -f5 -d' ') ; do for i in $(mmcli -m "$MODEM" --messaging-list-sms | grep " (sent)" | cut -f5 -d' ') ; do
mmcli -m $MODEM --messaging-delete-sms=$i mmcli -m "$MODEM" --messaging-delete-sms="$i"
done done
TIME="$(date --iso-8601=seconds)" TIME="$(date --iso-8601=seconds)"
mkdir -p $LOGDIR/$NUMBER mkdir -p "$LOGDIR/$NUMBER"
echo -ne "Sent to $NUMBER at $TIME:\n$TEXT\n\n" >> $LOGDIR/$NUMBER/sms.txt printf %b "Sent to $NUMBER at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUMBER/sms.txt"
echo -ne "$TIME\tsent_txt\t$NUMBER\t$TEXTSIZE chars\n" >> $LOGDIR/modemlog.tsv printf %b "$TIME\tsent_txt\t$NUMBER\t$TEXTSIZE chars\n" >> "$LOGDIR/modemlog.tsv"
err "Sent text message ok" err "Sent text message ok"
} }
@ -52,24 +52,23 @@ sendtextmenu() {
modem_n || err "Couldn't determine modem number - is modem online?" modem_n || err "Couldn't determine modem number - is modem online?"
# Prompt for number # Prompt for number
NUMBER=$( NUMBER="$(
echo -e "\nCancel\n$(textcontacts)" | printf %b "\nCancel\n$(textcontacts)" |
awk NF | awk NF |
sxmo_dmenu_with_kb.sh -p "Number" -fn "Terminus-20" -l 10 -c sxmo_dmenu_with_kb.sh -p "Number" -fn "Terminus-20" -l 10 -c
) )"
echo "$NUMBER" | grep -E "^Cancel$" && exit 1 echo "$NUMBER" | grep -E "^Cancel$" && exit 1
echo "$NUMBER" | grep -E '[0-9]+' || err "That doesn't seem like a valid number" echo "$NUMBER" | grep -E '[0-9]+' || err "That doesn't seem like a valid number"
# Compose first version of msg # Compose first version of msg
TEXT="$(editmsg $NUMBER 'Enter text message here')" TEXT="$(editmsg "$NUMBER" 'Enter text message here')"
while true while true
do do
CHARS=$(echo "$TEXT" | wc -c) CONFIRM="$(
CONFIRM=$( printf %b "Edit Message ($TEXT)\nSend to → $NUMBER\nCancel" |
echo -e "Edit Message ($TEXT)\nSend to → $NUMBER\nCancel" |
dmenu -c -idx 1 -p "Confirm" -fn "Terminus-20" -l 10 dmenu -c -idx 1 -p "Confirm" -fn "Terminus-20" -l 10
) )"
echo "$CONFIRM" | grep -E "^Send" && sendmsg "$NUMBER" "$TEXT" && exit 0 echo "$CONFIRM" | grep -E "^Send" && sendmsg "$NUMBER" "$TEXT" && exit 0
echo "$CONFIRM" | grep -E "^Cancel$" && exit 1 echo "$CONFIRM" | grep -E "^Cancel$" && exit 1
echo "$CONFIRM" | grep -E "^Edit Message" && TEXT="$(editmsg "$NUMBER" "$TEXT")" echo "$CONFIRM" | grep -E "^Edit Message" && TEXT="$(editmsg "$NUMBER" "$TEXT")"
@ -77,17 +76,17 @@ sendtextmenu() {
} }
tailtextlog() { tailtextlog() {
st -e tail -f $LOGDIR/$1/sms.txt st -e tail -f "$LOGDIR/$1/sms.txt"
} }
main() { main() {
# Display # Display
ENTRIES="$(echo -e "$(textcontacts)" | xargs -INUM echo NUM logfile)" ENTRIES="$(printf %b "$(textcontacts)" | xargs -INUM echo NUM logfile)"
ENTRIES="$(echo -e "Close Menu\nSend a Text\n$ENTRIES")" ENTRIES="$(printf %b "Close Menu\nSend a Text\n$ENTRIES")"
NUMBER="$(echo -e "$ENTRIES" | dmenu -p Texts -c -fn Terminus-20 -l 10)" NUMBER="$(printf %b "$ENTRIES" | dmenu -p Texts -c -fn Terminus-20 -l 10)"
echo $NUMBER | grep "Close Menu" && exit 1 echo "$NUMBER" | grep "Close Menu" && exit 1
echo $NUMBER | grep "Send a Text" && sendtextmenu && exit 1 echo "$NUMBER" | grep "Send a Text" && sendtextmenu && exit 1
tailtextlog "$(echo $NUMBER | sed 's/ logfile//g')" tailtextlog "$(echo "$NUMBER" | sed 's/ logfile//g')"
} }
main main

Loading…
Cancel
Save