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
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
NRECORDINGS="$(ls -1 "$RECDIR" | wc -l)"
NRECORDINGS="$(find "$RECDIR" -type f | wc -l)"
OPTION="$(
printf %b "Line Jack\nMicrophone\n($NRECORDINGS) Recordings\nClose Menu" |
dmenu -fn Terminus-30 -c -p "Record" -l 20

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

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

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

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

@ -1,4 +1,4 @@
#!/usr/bin/env sh
sxmo_setpineled $1 150
sxmo_setpineled "$1" 150
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)
setdelta() {
sxmo_setpinebacklight $(
cat $DEV/brightness |
xargs -IB echo B $1 |
sxmo_setpinebacklight "$(
xargs -IB echo B "$1" < $DEV/brightness |
bc |
xargs -INUM echo -e "$MIN\nNUM" | sort -n | tail -n1 |
xargs -INUM echo -e "$MAX\nNUM" | sort -n | head -n1
)
)"
dunstify -i 0 -u normal -r 999 "$(cat $DEV/brightness)/${MAX}"
}
up() {
setdelta "+${STEP}"
}
down() {
setdelta "-${STEP}"
}
$1 $2
"$1" "$2"

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

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

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

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

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

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

@ -5,7 +5,7 @@ change() {
sudo setup-timezone -z "$1"
echo 1 > /tmp/sxmo_bar
echo Timezone changed ok
read
read -r
}
menu() {
@ -18,4 +18,8 @@ menu() {
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
echo "Upgrade complete - reboot for all change to take effect"
read
read -r

@ -1,22 +1,20 @@
#!/usr/bin/env sh
if [[ ! -z "$1" ]]
if [ -n "$1" ]
then
# E.g. passed liked: sxmo_urlhandler.sh http://foo.com
URL=$1
URL="$1"
else
# Surf
WINDOW="$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')"
SURFURL=`xprop -id $WINDOW | grep URI | awk '{print $3}' | sed 's/\"//g'`
if [[ ! -z "$SURFURL" ]]
then
SURFURL="$(xprop -id "$WINDOW" | grep URI | awk '{print $3}' | sed 's/\"//g')"
if [ -n "$SURFURL" ]; then
URL="$SURFURL"
fi
# 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)'`
if [[ ! -z "$ISNORMBROWS" ]]
then
ISNORMBROWS="$(xprop -id "$(xdotool getactivewindow)" | grep -E 'WM_CLASS.*(Netsurf|Firefox)')"
if [ -n "$ISNORMBROWS" ]; then
xdotool key --clearmodifiers --delay 20 "ctrl+l" "ctrl+c"
sleep 0.2
URL="$(xclip -o)"
@ -39,7 +37,7 @@ COMMAND=$(
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
)
[[ -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"

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

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

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

@ -1,5 +1,10 @@
#!/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
# 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
err() {
echo $1 | dmenu -fn Terminus-20 -c -l 10
echo "$1" | dmenu -fn Terminus-20 -c -l 10
kill $$
}
modem_n() {
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
}
textcontacts() {
# 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() {
TMP="$(mktemp --suffix $1_msg)"
TMP="$(mktemp --suffix "$1_msg")"
echo "$2" > "$TMP"
TEXT="$(st -e $EDITOR $TMP)"
cat $TMP
TEXT="$(st -e $EDITOR "$TMP")"
cat "$TMP"
}
sendmsg() {
MODEM=$(modem_n)
MODEM="$(modem_n)"
NUMBER="$(echo "$1" | sed 's/^[+]//' | sed 's/^1//')"
TEXT="$2"
TEXTSIZE="$(echo "$TEXT" | wc -c)"
TEXTSIZE="${#TEXT}"
SMSNO=$(
mmcli -m $MODEM --messaging-create-sms="text='$TEXT',number=$NUMBER" |
grep -o [0-9]*$
)
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
mmcli -m $MODEM --messaging-delete-sms=$i
SMSNO="$(
mmcli -m "$MODEM" --messaging-create-sms="text='$TEXT',number=$NUMBER" |
grep -o "[0-9]*$"
)"
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
mmcli -m "$MODEM" --messaging-delete-sms="$i"
done
TIME="$(date --iso-8601=seconds)"
mkdir -p $LOGDIR/$NUMBER
echo -ne "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
mkdir -p "$LOGDIR/$NUMBER"
printf %b "Sent to $NUMBER at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUMBER/sms.txt"
printf %b "$TIME\tsent_txt\t$NUMBER\t$TEXTSIZE chars\n" >> "$LOGDIR/modemlog.tsv"
err "Sent text message ok"
}
@ -52,24 +52,23 @@ sendtextmenu() {
modem_n || err "Couldn't determine modem number - is modem online?"
# Prompt for number
NUMBER=$(
echo -e "\nCancel\n$(textcontacts)" |
NUMBER="$(
printf %b "\nCancel\n$(textcontacts)" |
awk NF |
sxmo_dmenu_with_kb.sh -p "Number" -fn "Terminus-20" -l 10 -c
)
)"
echo "$NUMBER" | grep -E "^Cancel$" && exit 1
echo "$NUMBER" | grep -E '[0-9]+' || err "That doesn't seem like a valid number"
# Compose first version of msg
TEXT="$(editmsg $NUMBER 'Enter text message here')"
TEXT="$(editmsg "$NUMBER" 'Enter text message here')"
while true
do
CHARS=$(echo "$TEXT" | wc -c)
CONFIRM=$(
echo -e "Edit Message ($TEXT)\nSend to → $NUMBER\nCancel" |
CONFIRM="$(
printf %b "Edit Message ($TEXT)\nSend to → $NUMBER\nCancel" |
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 "^Cancel$" && exit 1
echo "$CONFIRM" | grep -E "^Edit Message" && TEXT="$(editmsg "$NUMBER" "$TEXT")"
@ -77,17 +76,17 @@ sendtextmenu() {
}
tailtextlog() {
st -e tail -f $LOGDIR/$1/sms.txt
st -e tail -f "$LOGDIR/$1/sms.txt"
}
main() {
# Display
ENTRIES="$(echo -e "$(textcontacts)" | xargs -INUM echo NUM logfile)"
ENTRIES="$(echo -e "Close Menu\nSend a Text\n$ENTRIES")"
NUMBER="$(echo -e "$ENTRIES" | dmenu -p Texts -c -fn Terminus-20 -l 10)"
echo $NUMBER | grep "Close Menu" && exit 1
echo $NUMBER | grep "Send a Text" && sendtextmenu && exit 1
tailtextlog "$(echo $NUMBER | sed 's/ logfile//g')"
ENTRIES="$(printf %b "$(textcontacts)" | xargs -INUM echo NUM logfile)"
ENTRIES="$(printf %b "Close Menu\nSend a Text\n$ENTRIES")"
NUMBER="$(printf %b "$ENTRIES" | dmenu -p Texts -c -fn Terminus-20 -l 10)"
echo "$NUMBER" | grep "Close Menu" && exit 1
echo "$NUMBER" | grep "Send a Text" && sendtextmenu && exit 1
tailtextlog "$(echo "$NUMBER" | sed 's/ logfile//g')"
}
main

Loading…
Cancel
Save