Shellcheck and tabindent all scripts

This commit is contained in:
Miles Alan 2020-06-10 19:26:56 -05:00
parent bd5ead19e5
commit 049a93e5d8
25 changed files with 589 additions and 534 deletions

View file

@ -2,228 +2,248 @@
WIN=$(xdotool getwindowfocus)
programchoicesinit() {
XPROPOUT="$(xprop -id $(xdotool getactivewindow))"
WMCLASS="${1:-$(echo "$XPROPOUT" | grep WM_CLASS | cut -d ' ' -f3-)}"
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
# Userscripts menu
echo $WMCLASS | grep -i "userscripts" && CHOICES="$(
ls -1 $XDG_CONFIG_HOME/sxmo/userscripts |
sed 's/ /\\ /' |
awk '{printf "%s\t^ 0 ^ $XDG_CONFIG_HOME/sxmo/userscripts/%s \n", $0, $0}'
)" && WINNAME=Userscripts && return
# Scripts menu
echo $WMCLASS | grep -i "scripts" && CHOICES="$(echo "
Web Search ^ 0 ^ sxmo_websearch.sh
Files ^ 0 ^ sxmo_files.sh
Record ^ 0 ^ sxmo_record.sh
Timer ^ 0 ^ sxmo_timer.sh
Youtube ^ 0 ^ sxmo_youtube.sh video
Youtube (Audio) ^ 0 ^ sxmo_youtube.sh audio
Weather ^ 0 ^ sxmo_weather.sh
RSS ^ 0 ^ sxmo_rss.sh
")" && WINNAME=Scripts && return
# Apps menu
echo $WMCLASS | grep -i "applications" && CHOICES="$(echo "
Surf ^ 0 ^ surf
Netsurf ^ 0 ^ netsurf
Firefox ^ 0 ^ firefox
Sacc ^ 0 ^ st -e sacc i-logout.cz/1/bongusta
W3m ^ 0 ^ st -e w3m duck.com
Xcalc ^ 0 ^ xcalc
St ^ 0 ^ st
Foxtrotgps ^ 0 ^ foxtrotgps
")" && WINNAME=Apps && return
# System Control menu
echo $WMCLASS | grep -i "config" && CHOICES="$(echo "
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"
)
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
# 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
# MPV
echo $WMCLASS | grep -i "mpv" && CHOICES="$(echo "
Pause ^ 0 ^ key space
Seek ← ^ 1 ^ key Left
Seek → ^ 1 ^ key Right
App Volume ↑ ^ 1 ^ key 0
App Volume ↓ ^ 1 ^ key 9
Speed ↑ ^ 1 ^ key bracketright
Speed ↓ ^ 1 ^ key bracketleft
Screenshot ^ 1 ^ key s
Loopmark ^ 1 ^ key l
Info ^ 1 ^ key i
Seek Info ^ 1 ^ key o
")" && WINNAME=Mpv && return
# St
echo $WMCLASS | grep -i "st-256color" && STSELMODEON="$(echo "$XPROPOUT" | grep -E '^_ST_SELMODE.+=' | cut -d= -f2 | tr -d ' ')" && CHOICES="$(echo "
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';
printf %b '^ 0 ^ key Ctrl+Shift+s'
)
$([ $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
Scroll ↑ ^ 1 ^ key Ctrl+Shift+b
Scroll ↓ ^ 1 ^ key Ctrl+Shift+f
Invert ^ 1 ^ key Ctrl+Shift+x
Hotkeys ^ 0 ^ sxmo_appmenu.sh sthotkeys
")" && WINNAME=St && return
# St hotkeys
echo $WMCLASS | grep -i "sthotkeys" && CHOICES="$(echo "
Send Ctrl-C ^ 0 ^ key Ctrl+c
Send Ctrl-L ^ 0 ^ key Ctrl+l
Send Ctrl-D ^ 0 ^ key Ctrl+d
")" && WINNAME=St && return
# Netsurf
echo $WMCLASS | grep -i netsurf && CHOICES="$(echo "
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
# Surf
echo $WMCLASS | grep surf && CHOICES="$(echo "
Navigate ^ 0 ^ key Ctrl+g
Link Menu ^ 0 ^ key Ctrl+d
Pipe URL ^ 0 ^ sxmo_urlhandler.sh
Zoom + ^ 1 ^ key Ctrl+Shift+k
Zoom - ^ 1 ^ key Ctrl+Shift+j
Scroll ↑ ^ 1 ^ key Shift+space
Scroll ↓ ^ 1 ^ key space
JS Toggle ^ 1 ^ key Ctrl+Shift+s
History ← ^ 1 ^ key Ctrl+h
History → ^ 1 ^ key Ctrl+l
")" && WINNAME=Surf && return
# Firefox
echo $WMCLASS | grep -i firefox && CHOICES="$(echo "
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
# Foxtrot GPS
echo $WMCLASS | grep -i foxtrot && CHOICES="$(echo "
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
if echo "$WMCLASS" | grep -i "userscripts"; then
# Userscripts menu
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
elif echo "$WMCLASS" | grep -i "scripts"; then
# Scripts menu
CHOICES="
Web Search ^ 0 ^ sxmo_websearch.sh
Files ^ 0 ^ sxmo_files.sh
Record ^ 0 ^ sxmo_record.sh
Timer ^ 0 ^ sxmo_timer.sh
Youtube ^ 0 ^ sxmo_youtube.sh video
Youtube (Audio) ^ 0 ^ sxmo_youtube.sh audio
Weather ^ 0 ^ sxmo_weather.sh
RSS ^ 0 ^ sxmo_rss.sh
"
WINNAME=Scripts
elif echo "$WMCLASS" | grep -i "applications"; then
# Apps menu
CHOICES="
Surf ^ 0 ^ surf
Netsurf ^ 0 ^ netsurf
Firefox ^ 0 ^ firefox
Sacc ^ 0 ^ st -e sacc i-logout.cz/1/bongusta
W3m ^ 0 ^ st -e w3m duck.com
Xcalc ^ 0 ^ xcalc
St ^ 0 ^ st
Foxtrotgps ^ 0 ^ foxtrotgps
"
WINNAME=Apps
elif echo "$WMCLASS" | grep -i "config"; then
# System Control menu
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 $(
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
elif echo "$WMCLASS" | grep -i "audioout"; then
# Audio Out menu
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
CHOICES="
Pause ^ 0 ^ key space
Seek ← ^ 1 ^ key Left
Seek → ^ 1 ^ key Right
App Volume ↑ ^ 1 ^ key 0
App Volume ↓ ^ 1 ^ key 9
Speed ↑ ^ 1 ^ key bracketright
Speed ↓ ^ 1 ^ key bracketleft
Screenshot ^ 1 ^ key s
Loopmark ^ 1 ^ key l
Info ^ 1 ^ key i
Seek Info ^ 1 ^ key o
"
WINNAME=Mpv && return
elif echo "$WMCLASS" | grep -i "st-256color"; then
# St
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'
printf %b '^ 0 ^ key Ctrl+Shift+s'
)
$([ "$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
Scroll ↑ ^ 1 ^ key Ctrl+Shift+b
Scroll ↓ ^ 1 ^ key Ctrl+Shift+f
Invert ^ 1 ^ key Ctrl+Shift+x
Hotkeys ^ 0 ^ sxmo_appmenu.sh sthotkeys
"
WINNAME=St
elif echo "$WMCLASS" | grep -i "sthotkeys"; then
# St hotkeys
CHOICES="
Send Ctrl-C ^ 0 ^ key Ctrl+c
Send Ctrl-L ^ 0 ^ key Ctrl+l
Send Ctrl-D ^ 0 ^ key Ctrl+d
"
WINNAME=St
elif echo "$WMCLASS" | grep -i netsurf; then
# Netsurf
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
elif echo "$WMCLASS" | grep surf; then
# Surf
CHOICES="
Navigate ^ 0 ^ key Ctrl+g
Link Menu ^ 0 ^ key Ctrl+d
Pipe URL ^ 0 ^ sxmo_urlhandler.sh
Zoom + ^ 1 ^ key Ctrl+Shift+k
Zoom - ^ 1 ^ key Ctrl+Shift+j
Scroll ↑ ^ 1 ^ key Shift+space
Scroll ↓ ^ 1 ^ key space
JS Toggle ^ 1 ^ key Ctrl+Shift+s
History ← ^ 1 ^ key Ctrl+h
History → ^ 1 ^ key Ctrl+l
"
WINNAME=Surf
elif echo "$WMCLASS" | grep -i firefox; then
# Firefox
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
elif echo "$WMCLASS" | grep -i foxtrot; then
# Foxtrot GPS
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
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 $@
# E.g. sets CHOICES var
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)
$CHOICES
")"
# Decorate menu at top w/ incoming call entry if present
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="
$CHOICES
System Menu ^ 0 ^ sxmo_appmenu.sh sys
"
# Decorate menu at bottom w/ system menu entry if not system menu
echo $WINNAME | grep -v Sys && CHOICES="
$CHOICES
System Menu ^ 0 ^ sxmo_appmenu.sh sys
"
# Decorate menu at bottom w/ close menu entry
CHOICES="
$CHOICES
Close Menu ^ 0 ^ quit
"
# Decorate menu at bottom w/ close menu entry
CHOICES="
$CHOICES
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() {
xdotool windowactivate "$WIN"
xdotool key --clearmodifiers "$1"
#--window $WIN
xdotool windowactivate "$WIN"
xdotool key --clearmodifiers "$1"
#--window $WIN
}
quit() {
exit 0
exit 0
}
mainloop() {
DMENUIDX=0
PICKED=""
ARGS="$@"
DMENUIDX=0
PICKED=""
ARGS="$*"
while :
do
# E.g. sets PROGCHOICES
getprogchoices $ARGS
while :
do
# E.g. sets PROGCHOICES
getprogchoices "$ARGS"
PICKED="$(
echo "$PROGCHOICES" |
cut -d'^' -f1 |
dmenu -idx $DMENUIDX -l 14 -c -fn "Terminus-30" -p "$WINNAME"
)"
LOOP="$(echo "$PROGCHOICES" | grep -F "$PICKED" | cut -d '^' -f2)"
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
done
PICKED="$(
echo "$PROGCHOICES" |
cut -d'^' -f1 |
dmenu -idx $DMENUIDX -l 14 -c -fn "Terminus-30" -p "$WINNAME"
)"
LOOP="$(echo "$PROGCHOICES" | grep -F "$PICKED" | cut -d '^' -f2)"
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
done
}
pgrep -f sxmo_appmenu.sh | grep -Ev "^${$}$" | xargs kill -9
pkill -9 dmenu
mainloop $@
mainloop "$@"

View file

@ -1,9 +1,9 @@
#!/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
echo "None"
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"
}
audiodevice

View file

@ -9,12 +9,12 @@ amixer set "$SPEAKER" mute
amixer set "$HEADPHONE" mute
amixer set "$EARPIECE" mute
if [[ "$ARG" = "Speaker" ]]; then
amixer set "$SPEAKER" unmute
elif [[ "$ARG" = "Headphones" ]]; then
amixer set "$HEADPHONE" unmute
elif [[ "$ARG" = "Earpiece" ]]; then
amixer set "$EARPIECE" unmute
if [ "$ARG" = "Speaker" ]; then
amixer set "$SPEAKER" unmute
elif [ "$ARG" = "Headphones" ]; then
amixer set "$HEADPHONE" unmute
elif [ "$ARG" = "Earpiece" ]; then
amixer set "$EARPIECE" unmute
fi
echo 1 > /tmp/sxmo_bar

View file

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

View file

@ -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 |
bc |
xargs -INUM echo -e "$MIN\nNUM" | sort -n | tail -n1 |
xargs -INUM echo -e "$MAX\nNUM" | sort -n | head -n1
)
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}"
dunstify -i 0 -u normal -r 999 "$(cat $DEV/brightness)/${MAX}"
}
up() {
setdelta "+${STEP}"
setdelta "+${STEP}"
}
down() {
setdelta "-${STEP}"
setdelta "-${STEP}"
}
$1 $2
"$1" "$2"

View file

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

View file

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

View file

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

View file

@ -3,34 +3,37 @@ INPUT="$(cat)"
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
)"
pkill svkbd-sxmo
pidof svkbd-sxmo || svkbd-sxmo &
RESULT="$(
echo "Close Menu" &&
echo "$INPUT" |
grep -Eo '\S+' |
tr -d '[:blank:]' |
sort |
uniq |
dmenu -p "$PROMPT" -l 10 -i -c -fn Terminus-20
)"
pkill svkbd-sxmo
}
copy() {
PROMPT=Copy
menu
if [[ "$RESULT" = "Close Menu" ]]; then
exit 0
else
echo "$RESULT" | xclip -i
fi
PROMPT=Copy
menu
if [ "$RESULT" = "Close Menu" ]; then
exit 0
else
echo "$RESULT" | xclip -i
fi
}
type() {
PROMPT=Type
menu
if [[ "$RESULT" = "Close Menu" ]]; then
exit 0
else
xdotool type --window $STWIN "$RESULT"
fi
PROMPT=Type
menu
if [ "$RESULT" = "Close Menu" ]; then
exit 0
else
xdotool type --window "$STWIN" "$RESULT"
fi
}
$@
"$1"

View file

@ -2,43 +2,52 @@
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
MODEMMON=""
pgrep -f sxmo_modemmonitor.sh && MODEMMON="M "
# M symbol if modem monitoring is on & modem present
MODEMMON=""
pgrep -f sxmo_modemmonitor.sh && MODEMMON="M "
# Battery pct
PCT=$(cat /sys/class/power_supply/*-battery/capacity)
BATSTATUS=$(
cat /sys/class/power_supply/*-battery/status |
cut -c1
)
# Battery pct
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)"$(
amixer sget "$AUDIODEV" |
grep -oE '([0-9]+)%' |
tr -d ' %' |
awk '{ s += $1; c++ } END { print s/c }' |
xargs printf %.0f
)"
# Volume
AUDIODEV="$(sxmo_audiocurrentdevice.sh)"
[ "$AUDIODEV" = "None" ] && VOL="" || VOL=$(echo "$AUDIODEV" | cut -c1 | tr L S)"$(
amixer sget "$AUDIODEV" |
grep -oE '([0-9]+)%' |
tr -d ' %' |
awk '{ s += $1; c++ } END { print s/c }' |
xargs printf %.0f
)"
# Time
TIME=$(date +%R)
# Time
TIME="$(date +%R)"
BAR=" ${MODEMMON}${VOL} ${BATSTATUS}${PCT}% ${TIME}"
xsetroot -name "$BAR"
BAR=" ${MODEMMON}${VOL} ${BATSTATUS}${PCT}% ${TIME}"
xsetroot -name "$BAR"
}
# 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
update
inotifywait -e MODIFY "$UPDATEFILE"
done

View file

@ -10,67 +10,67 @@
SURF_WINDOW="${1:-$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')}"
DMENU_PROMPT="${2:-Link}"
function dump_links_with_titles() {
awk '{
input = $0;
dump_links_with_titles() {
awk '{
input = $0;
$0 = input;
gsub("<[^>]*>", "");
gsub(/[ ]+/, " ");
gsub("&amp;", "\\&");
gsub("&lt;", "<");
gsub("&gt;", ">");
$1 = $1;
title = ($0 == "" ? "None" : $0);
$0 = input;
gsub("<[^>]*>", "");
gsub(/[ ]+/, " ");
gsub("&amp;", "\\&");
gsub("&lt;", "<");
gsub("&gt;", ">");
$1 = $1;
title = ($0 == "" ? "None" : $0);
$0 = input;
match($0, /\<[ ]*[aA][^>]* [hH][rR][eE][fF]=["]([^"]+)["]/, linkextract);
$0 = linkextract[1];
gsub(/^[ \t]+/,"");
gsub(/[ \t]+$/,"");
gsub("[ ]", "%20");
link = $0;
$0 = input;
match($0, /\<[ ]*[aA][^>]* [hH][rR][eE][fF]=["]([^"]+)["]/, linkextract);
$0 = linkextract[1];
gsub(/^[ \t]+/,"");
gsub(/[ \t]+$/,"");
gsub("[ ]", "%20");
link = $0;
if (link != "") {
print title ": " link;
}
}'
if (link != "") {
print title ": " link;
}
}'
}
function link_normalize() {
URI=$1
awk -v uri=$URI '{
gsub("&amp;", "\\&");
link_normalize() {
URI=$1
awk -v uri="$URI" '{
gsub("&amp;", "\\&");
if ($0 ~ /^https?:\/\// || $0 ~ /^\/\/.+$/) {
print $0;
} else if ($0 ~/^#/) {
gsub(/[#?][^#?]+/, "", uri);
print uri $0;
} else if ($0 ~/^\//) {
split(uri, uri_parts, "/");
print uri_parts[3] $0;
} else {
gsub(/[#][^#]+/, "", uri);
uri_parts_size = split(uri, uri_parts, "/");
delete uri_parts[uri_parts_size];
for (v in uri_parts) {
uri_pagestripped = uri_pagestripped uri_parts[v] "/"
}
print uri_pagestripped $0;
}
}'
if ($0 ~ /^https?:\/\// || $0 ~ /^\/\/.+$/) {
print $0;
} else if ($0 ~/^#/) {
gsub(/[#?][^#?]+/, "", uri);
print uri $0;
} else if ($0 ~/^\//) {
split(uri, uri_parts, "/");
print uri_parts[3] $0;
} else {
gsub(/[#][^#]+/, "", uri);
uri_parts_size = split(uri, uri_parts, "/");
delete uri_parts[uri_parts_size];
for (v in uri_parts) {
uri_pagestripped = uri_pagestripped uri_parts[v] "/"
}
print uri_pagestripped $0;
}
}'
}
function link_select() {
tr '\n\r' ' ' |
xmllint --html --xpath "//a" - |
dump_links_with_titles |
awk '!x[$0]++' |
# 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_select() {
tr '\n\r' ' ' |
xmllint --html --xpath "//a" - |
dump_links_with_titles |
awk '!x[$0]++' |
# 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)"
}
pidof svkbd-sxmo || svkbd-sxmo &

View file

@ -1,21 +1,25 @@
#!/usr/bin/env sh
change() {
echo "Changing timezone to $1"
sudo setup-timezone -z "$1"
echo 1 > /tmp/sxmo_bar
echo Timezone changed ok
read
echo "Changing timezone to $1"
sudo setup-timezone -z "$1"
echo 1 > /tmp/sxmo_bar
echo Timezone changed ok
read -r
}
menu() {
T="$(
find /usr/share/zoneinfo -type f |
sed 's#^/usr/share/zoneinfo/##g' |
sort |
sxmo_dmenu_with_kb.sh -p Timezone -c -l 10 -fn Terminus-20 -i
)"
st -e "$0" change "$T"
T="$(
find /usr/share/zoneinfo -type f |
sed 's#^/usr/share/zoneinfo/##g' |
sort |
sxmo_dmenu_with_kb.sh -p Timezone -c -l 10 -fn Terminus-20 -i
)"
st -e "$0" change "$T"
}
[ $# -gt 0 ] && $@ || menu
if [ $# -gt 0 ]; then
"$1" "$2"
else
menu
fi

View file

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

View file

@ -1,45 +1,43 @@
#!/usr/bin/env sh
if [[ ! -z "$1" ]]
if [ -n "$1" ]
then
# E.g. passed liked: sxmo_urlhandler.sh http://foo.com
URL=$1
# E.g. passed liked: sxmo_urlhandler.sh http://foo.com
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
URL="$SURFURL"
fi
# Surf
WINDOW="$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')"
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
xdotool key --clearmodifiers --delay 20 "ctrl+l" "ctrl+c"
sleep 0.2
URL="$(xclip -o)"
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 [ -n "$ISNORMBROWS" ]; then
xdotool key --clearmodifiers --delay 20 "ctrl+l" "ctrl+c"
sleep 0.2
URL="$(xclip -o)"
fi
fi
COMMAND=$(
echo "
w3m URL
mpv -v URL
mpv -v --ytdl-format='[height<420]' URL
firefox -new-window URL
netsurf URL
surf URL
echo URL | xsel -i
youtube-dl -o- URL | mpv -v -
youtube-dl URL
curl URL | vis -
wget 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
echo "
w3m URL
mpv -v URL
mpv -v --ytdl-format='[height<420]' URL
firefox -new-window URL
netsurf URL
surf URL
echo URL | xsel -i
youtube-dl -o- URL | mpv -v -
youtube-dl URL
curl URL | vis -
wget 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
)
[[ -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"

View file

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