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. 49
      scripts/appscripts/sxmo_rss.sh
  4. 20
      scripts/appscripts/sxmo_weather.sh
  5. 2
      scripts/appscripts/sxmo_websearch.sh
  6. 438
      scripts/core/sxmo_appmenu.sh
  7. 8
      scripts/core/sxmo_audiocurrentdevice.sh
  8. 12
      scripts/core/sxmo_audioout.sh
  9. 4
      scripts/core/sxmo_blinkled.sh
  10. 22
      scripts/core/sxmo_brightness.sh
  11. 1
      scripts/core/sxmo_dmenu_with_kb.sh
  12. 2
      scripts/core/sxmo_edit_screen.sh
  13. 4
      scripts/core/sxmo_flashtoggle.sh
  14. 49
      scripts/core/sxmo_pipecomplete.sh
  15. 69
      scripts/core/sxmo_statusbar.sh
  16. 106
      scripts/core/sxmo_surf_linkselect.sh
  17. 30
      scripts/core/sxmo_timezonechange.sh
  18. 2
      scripts/core/sxmo_upgrade.sh
  19. 66
      scripts/core/sxmo_urlhandler.sh
  20. 1
      scripts/core/sxmo_xinit.sh
  21. 131
      scripts/modem/sxmo_modemcall.sh
  22. 6
      scripts/modem/sxmo_modeminfo.sh
  23. 47
      scripts/modem/sxmo_modemmonitor.sh
  24. 7
      scripts/modem/sxmo_modemmonitortoggle.sh
  25. 69
      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,31 +1,42 @@
#!/usr/bin/env sh #!/usr/bin/env sh
SFEEDCONF=/usr/share/sxmo/sxmo_sfeedrc 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
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
# coreutils is a dep... # coreutils is a dep...
TIME=$(eval date -d \""$TIMESPAN"\" +%s) TIME=$(eval date -d \""$TIMESPAN"\" +%s)
cat | gawk "\$1 > $TIME" cat | gawk "\$1 > $TIME"
} }
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 |\
gawk -F' ' '{printf strftime("%y/%m/%d %H:%M",$1); $1=""; print $0}' gawk -F' ' '{printf strftime("%y/%m/%d %H:%M",$1); $1=""; print $0}'
} }
# Update Sfeed # Update Sfeed

@ -2,16 +2,16 @@
pidof svkbd-sxmo || svkbd-sxmo & pidof svkbd-sxmo || svkbd-sxmo &
ZIP=$( ZIP=$(
printf %b " printf %b "
10025 - NYC 10025 - NYC
60007 - Chicago 60007 - Chicago
94016 - San Francisco 94016 - San Francisco
97035 - Portland, OR 97035 - Portland, OR
" | " |
awk 'NF' | awk 'NF' |
awk '{$1=$1};1' | awk '{$1=$1};1' |
dmenu -fn Terminus-20 -i -c -l 10 -p "US Zipcode" | dmenu -fn Terminus-20 -i -c -l 10 -p "US Zipcode" |
awk -F " " '{print $1}' awk -F " " '{print $1}'
) )
pkill svkbd-sxmo pkill svkbd-sxmo

@ -1,7 +1,7 @@
#!/usr/bin/env sh #!/usr/bin/env sh
pidof svkbd-sxmo || svkbd-sxmo & pidof svkbd-sxmo || svkbd-sxmo &
SEARCHQUERY="$( SEARCHQUERY="$(
echo "Close Menu" | dmenu -t -p "Search Query:" -c -fn "Terminus-20" -l 20 echo "Close Menu" | dmenu -t -p "Search Query:" -c -fn "Terminus-20" -l 20
)" )"
pkill svkbd-sxmo pkill svkbd-sxmo
echo "$SEARCHQUERY" | grep . || exit 0 echo "$SEARCHQUERY" | grep . || exit 0

@ -2,228 +2,248 @@
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 " # Userscripts menu
$( CHOICES="$(
[ -n "$(ls -A $XDG_CONFIG_HOME/sxmo/userscripts)" ] && find "$XDG_CONFIG_HOME/sxmo/userscripts" -type f -print0 |
echo 'Userscripts ^ 0 ^ sxmo_appmenu.sh userscripts' xargs -IF basename F |
) awk '{printf "%s\t^ 0 ^ $XDG_CONFIG_HOME/sxmo/userscripts/%s \n", $0, $0}'
Scripts ^ 0 ^ sxmo_appmenu.sh scripts )"
Apps ^ 0 ^ sxmo_appmenu.sh applications WINNAME=Userscripts
Volume ↑ ^ 1 ^ sxmo_vol.sh up elif echo "$WMCLASS" | grep -i "scripts"; then
Volume ↓ ^ 1 ^ sxmo_vol.sh down # Scripts menu
Dialer ^ 0 ^ sxmo_modemcall.sh dial CHOICES="
Texts ^ 0 ^ sxmo_modemtext.sh Web Search ^ 0 ^ sxmo_websearch.sh
Camera ^ 0 ^ sxmo_camera.sh Files ^ 0 ^ sxmo_files.sh
Wifi ^ 0 ^ st -e "nmtui" Record ^ 0 ^ sxmo_record.sh
Audio ^ 0 ^ sxmo_appmenu.sh audioout Timer ^ 0 ^ sxmo_timer.sh
Config ^ 0 ^ sxmo_appmenu.sh config Youtube ^ 0 ^ sxmo_youtube.sh video
Logout ^ 0 ^ pkill -9 dwm Youtube (Audio) ^ 0 ^ sxmo_youtube.sh audio
")" && WINNAME=Sys Weather ^ 0 ^ sxmo_weather.sh
RSS ^ 0 ^ sxmo_rss.sh
# Userscripts menu "
echo $WMCLASS | grep -i "userscripts" && CHOICES="$( WINNAME=Scripts
ls -1 $XDG_CONFIG_HOME/sxmo/userscripts | elif echo "$WMCLASS" | grep -i "applications"; then
sed 's/ /\\ /' | # Apps menu
awk '{printf "%s\t^ 0 ^ $XDG_CONFIG_HOME/sxmo/userscripts/%s \n", $0, $0}' CHOICES="
)" && WINNAME=Userscripts && return Surf ^ 0 ^ surf
Netsurf ^ 0 ^ netsurf
# Scripts menu Firefox ^ 0 ^ firefox
echo $WMCLASS | grep -i "scripts" && CHOICES="$(echo " Sacc ^ 0 ^ st -e sacc i-logout.cz/1/bongusta
Web Search ^ 0 ^ sxmo_websearch.sh W3m ^ 0 ^ st -e w3m duck.com
Files ^ 0 ^ sxmo_files.sh Xcalc ^ 0 ^ xcalc
Record ^ 0 ^ sxmo_record.sh St ^ 0 ^ st
Timer ^ 0 ^ sxmo_timer.sh Foxtrotgps ^ 0 ^ foxtrotgps
Youtube ^ 0 ^ sxmo_youtube.sh video "
Youtube (Audio) ^ 0 ^ sxmo_youtube.sh audio WINNAME=Apps
Weather ^ 0 ^ sxmo_weather.sh elif echo "$WMCLASS" | grep -i "config"; then
RSS ^ 0 ^ sxmo_rss.sh # System Control menu
")" && WINNAME=Scripts && return CHOICES="
Brightesss ↑ ^ 1 ^ sxmo_brightness.sh up
# Apps menu Brightness ↓ ^ 1 ^ sxmo_brightness.sh down
echo $WMCLASS | grep -i "applications" && CHOICES="$(echo " Modem Toggle ^ 1 ^ sxmo_modemmonitortoggle.sh
Surf ^ 0 ^ surf Modem Info ^ 0 ^ sxmo_modeminfo.sh
Netsurf ^ 0 ^ netsurf Modem Log ^ 0 ^ sxmo_modemlog.sh
Firefox ^ 0 ^ firefox Flash $(
Sacc ^ 0 ^ st -e sacc i-logout.cz/1/bongusta grep -qE '^0$' /sys/class/leds/white:flash/brightness &&
W3m ^ 0 ^ st -e w3m duck.com printf %b "Off → On" || printf %b "On → Off";
Xcalc ^ 0 ^ xcalc printf %b "^ 1 ^ sxmo_flashtoggle.sh"
St ^ 0 ^ st )
Foxtrotgps ^ 0 ^ foxtrotgps Bar Toggle ^ 1 ^ key Alt+b
")" && WINNAME=Apps && return Change Timezone ^ 1 ^ sxmo_timezonechange.sh
Rotate ^ 1 ^ sxmo_rotate.sh
# System Control menu Upgrade Pkgs ^ 0 ^ st -e sxmo_upgrade.sh
echo $WMCLASS | grep -i "config" && CHOICES="$(echo " "
Brightesss ↑ ^ 1 ^ sxmo_brightness.sh up WINNAME=Config
Brightness ↓ ^ 1 ^ sxmo_brightness.sh down elif echo "$WMCLASS" | grep -i "audioout"; then
Modem Toggle ^ 1 ^ sxmo_modemmonitortoggle.sh # Audio Out menu
Modem Info ^ 0 ^ sxmo_modeminfo.sh CURRENTDEV="$(sxmo_audiocurrentdevice.sh)"
Modem Log ^ 0 ^ sxmo_modemlog.sh CHOICES="
Flash $( Headphones $([ "$CURRENTDEV" = "Headphone" ] && echo "✓") ^ 1 ^ sxmo_audioout.sh Headphones
cat /sys/class/leds/white:flash/brightness | Speaker $([ "$CURRENTDEV" = "Line Out" ] && echo "✓") ^ 1 ^ sxmo_audioout.sh Speaker
grep -E '^0$' > /dev/null && Earpiece $([ "$CURRENTDEV" = "Earpiece" ] && echo "✓") ^ 1 ^ sxmo_audioout.sh Earpiece
echo -n "Off → On" || echo -n "On → Off"; None $([ "$CURRENTDEV" = "None" ] && echo "✓") ^ 1 ^ sxmo_audioout.sh None
echo -n "^ 1 ^ sxmo_flashtoggle.sh" "
) WINNAME="Audio"
Bar Toggle ^ 1 ^ key Alt+b elif echo "$WMCLASS" | grep -i "mpv"; then
Change Timezone ^ 1 ^ sxmo_timezonechange.sh # MPV
Rotate ^ 1 ^ sxmo_rotate.sh CHOICES="
Upgrade Pkgs ^ 0 ^ st -e sxmo_upgrade.sh Pause ^ 0 ^ key space
")" && WINNAME=Config && return Seek ← ^ 1 ^ key Left
Seek → ^ 1 ^ key Right
# Audio Out menu App Volume ↑ ^ 1 ^ key 0
echo $WMCLASS | grep -i "audioout" && CURRENTDEV="$(sxmo_audiocurrentdevice.sh)" && CHOICES="$(echo " App Volume ↓ ^ 1 ^ key 9
Headphones $([[ "$CURRENTDEV" == "Headphone" ]] && echo "✓") ^ 1 ^ sxmo_audioout.sh Headphones Speed ↑ ^ 1 ^ key bracketright
Speaker $([[ "$CURRENTDEV" == "Line Out" ]] && echo "✓") ^ 1 ^ sxmo_audioout.sh Speaker Speed ↓ ^ 1 ^ key bracketleft
Earpiece $([[ "$CURRENTDEV" == "Earpiece" ]] && echo "✓") ^ 1 ^ sxmo_audioout.sh Earpiece Screenshot ^ 1 ^ key s
None $([[ "$CURRENTDEV" == "None" ]] && echo "✓") ^ 1 ^ sxmo_audioout.sh None Loopmark ^ 1 ^ key l
")" && WINNAME="Audio" && return Info ^ 1 ^ key i
Seek Info ^ 1 ^ key o
# MPV "
echo $WMCLASS | grep -i "mpv" && CHOICES="$(echo " WINNAME=Mpv && return
Pause ^ 0 ^ key space elif echo "$WMCLASS" | grep -i "st-256color"; then
Seek ← ^ 1 ^ key Left # St
Seek → ^ 1 ^ key Right STSELMODEON="$(
App Volume ↑ ^ 1 ^ key 0 echo "$XPROPOUT" | grep -E '^_ST_SELMODE.+=' | cut -d= -f2 | tr -d ' '
App Volume ↓ ^ 1 ^ key 9 )"
Speed ↑ ^ 1 ^ key bracketright CHOICES="
Speed ↓ ^ 1 ^ key bracketleft Type complete ^ 0 ^ key Ctrl+Shift+u
Screenshot ^ 1 ^ key s Copy complete ^ 0 ^ key Ctrl+Shift+i
Loopmark ^ 1 ^ key l Selmode $(
Info ^ 1 ^ key i [ "$STSELMODEON" = 1 ] &&
Seek Info ^ 1 ^ key o printf %b 'On → Off' ||
")" && WINNAME=Mpv && return printf %b 'Off → On'
printf %b '^ 0 ^ key Ctrl+Shift+s'
# St )
echo $WMCLASS | grep -i "st-256color" && STSELMODEON="$(echo "$XPROPOUT" | grep -E '^_ST_SELMODE.+=' | cut -d= -f2 | tr -d ' ')" && CHOICES="$(echo " $([ "$STSELMODEON" = 1 ] && echo 'Copy selection ^ 0 ^ key Ctrl+Shift+c')
Type complete ^ 0 ^ key Ctrl+Shift+u Paste ^ 0 ^ key Ctrl+Shift+v
Copy complete ^ 0 ^ key Ctrl+Shift+i Zoom + ^ 1 ^ key Ctrl+Shift+Prior
Selmode $( Zoom - ^ 1 ^ key Ctrl+Shift+Next
[ $STSELMODEON == 1 ] && printf %b 'On → Off' || printf %b 'Off → On'; Scroll ↑ ^ 1 ^ key Ctrl+Shift+b
printf %b '^ 0 ^ key Ctrl+Shift+s' Scroll ↓ ^ 1 ^ key Ctrl+Shift+f
) Invert ^ 1 ^ key Ctrl+Shift+x
$([ $STSELMODEON == 1 ] && echo 'Copy selection ^ 0 ^ key Ctrl+Shift+c') Hotkeys ^ 0 ^ sxmo_appmenu.sh sthotkeys
Paste ^ 0 ^ key Ctrl+Shift+v "
Zoom + ^ 1 ^ key Ctrl+Shift+Prior WINNAME=St
Zoom - ^ 1 ^ key Ctrl+Shift+Next elif echo "$WMCLASS" | grep -i "sthotkeys"; then
Scroll ↑ ^ 1 ^ key Ctrl+Shift+b # St hotkeys
Scroll ↓ ^ 1 ^ key Ctrl+Shift+f CHOICES="
Invert ^ 1 ^ key Ctrl+Shift+x Send Ctrl-C ^ 0 ^ key Ctrl+c
Hotkeys ^ 0 ^ sxmo_appmenu.sh sthotkeys Send Ctrl-L ^ 0 ^ key Ctrl+l
")" && WINNAME=St && return Send Ctrl-D ^ 0 ^ key Ctrl+d
"
# St hotkeys WINNAME=St
echo $WMCLASS | grep -i "sthotkeys" && CHOICES="$(echo " elif echo "$WMCLASS" | grep -i netsurf; then
Send Ctrl-C ^ 0 ^ key Ctrl+c # Netsurf
Send Ctrl-L ^ 0 ^ key Ctrl+l CHOICES="
Send Ctrl-D ^ 0 ^ key Ctrl+d Pipe URL ^ 0 ^ sxmo_urlhandler.sh
")" && WINNAME=St && return Zoom + ^ 1 ^ key Ctrl+plus
Zoom - ^ 1 ^ key Ctrl+minus
# Netsurf History ← ^ 1 ^ key Alt+Left
echo $WMCLASS | grep -i netsurf && CHOICES="$(echo " History → ^ 1 ^ key Alt+Right
Pipe URL ^ 0 ^ sxmo_urlhandler.sh "
Zoom + ^ 1 ^ key Ctrl+plus WINNAME=Netsurf
Zoom - ^ 1 ^ key Ctrl+minus elif echo "$WMCLASS" | grep surf; then
History ← ^ 1 ^ key Alt+Left # Surf
History → ^ 1 ^ key Alt+Right CHOICES="
")" && WINNAME=Netsurf && return Navigate ^ 0 ^ key Ctrl+g
Link Menu ^ 0 ^ key Ctrl+d
# Surf Pipe URL ^ 0 ^ sxmo_urlhandler.sh
echo $WMCLASS | grep surf && CHOICES="$(echo " Zoom + ^ 1 ^ key Ctrl+Shift+k
Navigate ^ 0 ^ key Ctrl+g Zoom - ^ 1 ^ key Ctrl+Shift+j
Link Menu ^ 0 ^ key Ctrl+d Scroll ↑ ^ 1 ^ key Shift+space
Pipe URL ^ 0 ^ sxmo_urlhandler.sh Scroll ↓ ^ 1 ^ key space
Zoom + ^ 1 ^ key Ctrl+Shift+k JS Toggle ^ 1 ^ key Ctrl+Shift+s
Zoom - ^ 1 ^ key Ctrl+Shift+j History ← ^ 1 ^ key Ctrl+h
Scroll ↑ ^ 1 ^ key Shift+space History → ^ 1 ^ key Ctrl+l
Scroll ↓ ^ 1 ^ key space "
JS Toggle ^ 1 ^ key Ctrl+Shift+s WINNAME=Surf
History ← ^ 1 ^ key Ctrl+h elif echo "$WMCLASS" | grep -i firefox; then
History → ^ 1 ^ key Ctrl+l # Firefox
")" && WINNAME=Surf && return CHOICES="
Pipe URL ^ 0 ^ sxmo_urlhandler.sh
# Firefox Zoom + ^ 1 ^ key Ctrl+plus
echo $WMCLASS | grep -i firefox && CHOICES="$(echo " Zoom - ^ 1 ^ key Ctrl+minus
Pipe URL ^ 0 ^ sxmo_urlhandler.sh History ← ^ 1 ^ key Alt+Left
Zoom + ^ 1 ^ key Ctrl+plus History → ^ 1 ^ key Alt+Right
Zoom - ^ 1 ^ key Ctrl+minus "
History ← ^ 1 ^ key Alt+Left WINNAME=Firefox
History → ^ 1 ^ key Alt+Right elif echo "$WMCLASS" | grep -i foxtrot; then
")" && WINNAME=Firefox && return # Foxtrot GPS
CHOICES="
# Foxtrot GPS Zoom + ^ 1 ^ key i
echo $WMCLASS | grep -i foxtrot && CHOICES="$(echo " Zoom - ^ 1 ^ key o
Zoom + ^ 1 ^ key i Panel toggle ^ 1 ^ key m
Zoom - ^ 1 ^ key o Autocenter toggle ^ 0 ^ key a
Panel toggle ^ 1 ^ key m Route ^ 0 ^ key r
Autocenter toggle ^ 0 ^ key a "
Route ^ 0 ^ key r WINNAME=Gps
")" && WINNAME=Gps && return 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="
$CHOICES $CHOICES
System Menu ^ 0 ^ sxmo_appmenu.sh sys System Menu ^ 0 ^ sxmo_appmenu.sh sys
" "
# Decorate menu at bottom w/ close menu entry # Decorate menu at bottom w/ close menu entry
CHOICES=" CHOICES="
$CHOICES $CHOICES
Close Menu ^ 0 ^ quit Close Menu ^ 0 ^ quit
" "
PROGCHOICES="$(echo "$CHOICES" | xargs -0 echo | sed '/^[[:space:]]*$/d' | awk '{$1=$1};1')" PROGCHOICES="$(echo "$CHOICES" | xargs -0 echo | sed '/^[[:space:]]*$/d' | awk '{$1=$1};1')"
} }
key() { key() {
xdotool windowactivate "$WIN" xdotool windowactivate "$WIN"
xdotool key --clearmodifiers "$1" xdotool key --clearmodifiers "$1"
#--window $WIN #--window $WIN
} }
quit() { quit() {
exit 0 exit 0
} }
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" |
cut -d'^' -f1 | cut -d'^' -f1 |
dmenu -idx $DMENUIDX -l 14 -c -fn "Terminus-30" -p "$WINNAME" dmenu -idx $DMENUIDX -l 14 -c -fn "Terminus-30" -p "$WINNAME"
)" )"
LOOP="$(echo "$PROGCHOICES" | grep -F "$PICKED" | cut -d '^' -f2)" LOOP="$(echo "$PROGCHOICES" | grep -F "$PICKED" | cut -d '^' -f2)"
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,9 +1,9 @@
#!/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"
} }
audiodevice audiodevice

@ -9,12 +9,12 @@ 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
echo 1 > /tmp/sxmo_bar echo 1 > /tmp/sxmo_bar

@ -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
)" )"

@ -3,34 +3,37 @@ INPUT="$(cat)"
STWIN="$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')" 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" |
echo "$INPUT" | grep -Eo '\S+' | tr -d '[:blank:]' | sort | uniq grep -Eo '\S+' |
)" | dmenu -p "$PROMPT" -l 10 -i -c -fn Terminus-20 tr -d '[:blank:]' |
)" sort |
pkill svkbd-sxmo uniq |
dmenu -p "$PROMPT" -l 10 -i -c -fn Terminus-20
)"
pkill svkbd-sxmo
} }
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
fi fi
} }
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,43 +2,52 @@
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
MODEMMON="" MODEMMON=""
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 ' %' |
awk '{ s += $1; c++ } END { print s/c }' | awk '{ s += $1; c++ } END { print s/c }' |
xargs printf %.0f xargs printf %.0f
)" )"
# 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"
} }
# 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,67 +10,67 @@
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;
$0 = input; $0 = input;
gsub("<[^>]*>", ""); gsub("<[^>]*>", "");
gsub(/[ ]+/, " "); gsub(/[ ]+/, " ");
gsub("&amp;", "\\&"); gsub("&amp;", "\\&");
gsub("&lt;", "<"); gsub("&lt;", "<");
gsub("&gt;", ">"); gsub("&gt;", ">");
$1 = $1; $1 = $1;
title = ($0 == "" ? "None" : $0); title = ($0 == "" ? "None" : $0);
$0 = input; $0 = input;
match($0, /\<[ ]*[aA][^>]* [hH][rR][eE][fF]=["]([^"]+)["]/, linkextract); match($0, /\<[ ]*[aA][^>]* [hH][rR][eE][fF]=["]([^"]+)["]/, linkextract);
$0 = linkextract[1]; $0 = linkextract[1];
gsub(/^[ \t]+/,""); gsub(/^[ \t]+/,"");
gsub(/[ \t]+$/,""); gsub(/[ \t]+$/,"");
gsub("[ ]", "%20"); gsub("[ ]", "%20");
link = $0; link = $0;
if (link != "") { if (link != "") {
print title ": " link; print title ": " link;
} }
}' }'
} }
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 ~ /^\/\/.+$/) {
print $0; print $0;
} else if ($0 ~/^#/) { } else if ($0 ~/^#/) {
gsub(/[#?][^#?]+/, "", uri); gsub(/[#?][^#?]+/, "", uri);
print uri $0; print uri $0;
} else if ($0 ~/^\//) { } else if ($0 ~/^\//) {
split(uri, uri_parts, "/"); split(uri, uri_parts, "/");
print uri_parts[3] $0; print uri_parts[3] $0;
} else { } else {
gsub(/[#][^#]+/, "", uri); gsub(/[#][^#]+/, "", uri);
uri_parts_size = split(uri, uri_parts, "/"); uri_parts_size = split(uri, uri_parts, "/");
delete uri_parts[uri_parts_size]; delete uri_parts[uri_parts_size];
for (v in uri_parts) { for (v in uri_parts) {
uri_pagestripped = uri_pagestripped uri_parts[v] "/" uri_pagestripped = uri_pagestripped uri_parts[v] "/"
} }
print uri_pagestripped $0; print uri_pagestripped $0;
} }
}' }'
} }
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 |
awk '!x[$0]++' | awk '!x[$0]++' |
# 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 &

@ -1,21 +1,25 @@
#!/usr/bin/env sh #!/usr/bin/env sh
change() { change() {
echo "Changing timezone to $1" echo "Changing timezone to $1"
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() {
T="$( T="$(
find /usr/share/zoneinfo -type f | find /usr/share/zoneinfo -type f |
sed 's#^/usr/share/zoneinfo/##g' | sed 's#^/usr/share/zoneinfo/##g' |
sort | sort |
sxmo_dmenu_with_kb.sh -p Timezone -c -l 10 -fn Terminus-20 -i sxmo_dmenu_with_kb.sh -p Timezone -c -l 10 -fn Terminus-20 -i
)" )"
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,45 +1,43 @@
#!/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)" fi
fi
fi fi
COMMAND=$( COMMAND=$(
echo " echo "
w3m URL w3m URL
mpv -v URL mpv -v URL
mpv -v --ytdl-format='[height<420]' URL mpv -v --ytdl-format='[height<420]' URL
firefox -new-window URL firefox -new-window URL
netsurf URL netsurf URL
surf URL surf URL
echo URL | xsel -i echo URL | xsel -i
youtube-dl -o- URL | mpv -v - youtube-dl -o- URL | mpv -v -
youtube-dl URL youtube-dl URL
curl URL | vis - curl URL | vis -
wget URL wget URL
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,14 +21,16 @@ 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"
} }
vid_to_number() { vid_to_number() {
mmcli -m "$(modem_n)" -o "$1" -K | grep call.properties.number | cut -d ':' -f2 | tr -d ' ' | sed 's/^[+]//' | sed 's/^1//' mmcli -m "$(modem_n)" -o "$1" -K | grep call.properties.number | cut -d ':' -f2 | tr -d ' ' | sed 's/^[+]//' | sed 's/^1//'
} }
log_event() { log_event() {
@ -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"
} }
@ -107,69 +110,67 @@ hangup() {
} }
incallmenu() { incallmenu() {
DMENUIDX=0 DMENUIDX=0
VID="$1" VID="$1"
NUMBER="$(vid_to_number "$VID")" NUMBER="$(vid_to_number "$VID")"
# E.g. There's some bug with the modem that' requires us to toggle the # E.g. There's some bug with the modem that' requires us to toggle the
# DAI a few times before starting the call for it to kick in # DAI a few times before starting the call for it to kick in
FLAGS=" " FLAGS=" "
toggleflagset "-e" toggleflagset "-e"
toggleflagset "-m" toggleflagset "-m"
toggleflagset "-2" toggleflagset "-2"
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 &' "
"
PICKED=""
PICKED="" PICKED=$(
PICKED=$( echo "$CHOICES" |
echo "$CHOICES" | xargs -0 echo |
xargs -0 echo | cut -d'^' -f1 |
cut -d'^' -f1 | sed '/^[[:space:]]*$/d' |
sed '/^[[:space:]]*$/d' | awk '{$1=$1};1' |
awk '{$1=$1};1' | dmenu -idx $DMENUIDX -l 14 -c -fn "Terminus-30" -p "$NUMBER"
dmenu -idx $DMENUIDX -l 14 -c -fn "Terminus-30" -p "$NUMBER"
) )
# E.g. in modem watcher script we just kill dmenu if the other side hangsup # E.g. in modem watcher script we just kill dmenu if the other side hangsup
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
} }
dtmfmenu() { dtmfmenu() {
VID="$1" VID="$1"
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" )"
)" echo "$PICKED" | grep "Return to Call Menu" && return
echo "$PICKED" | grep "Return to Call Menu" && return DTMFINDEX=$(echo "$NUMS" | grep -bo "$PICKED" | cut -d: -f1 | xargs -IN echo 2+N | bc)
DTMFINDEX=$(echo "$NUMS" | grep -bo "$PICKED" | cut -d: -f1 | xargs -IN echo 2+N | bc) modem_cmd_errcheck -m "$(modem_n)" -o "$VID" --send-dtmf="$PICKED"
modem_cmd_errcheck -m "$(modem_n)" -o "$VID" --send-dtmf="$PICKED" done
done
} }
dial() { dial() {
@ -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"

@ -6,9 +6,9 @@ err() {
} }
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 -oE 'Modem\/([0-9]+)' > /dev/null || 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
} }
st -e sh -c "mmcli -m $(modem_n) && read" st -e sh -c "mmcli -m $(modem_n) && read"

@ -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