Initial commit

This commit is contained in:
Miles Alan 2020-03-15 18:42:35 -05:00
commit 8ae9fbdb1c
23 changed files with 1246 additions and 0 deletions

138
scripts/sxmo_appmenu.sh Executable file
View file

@ -0,0 +1,138 @@
#!/usr/bin/env sh
WIN=$(xdotool getwindowfocus)
programchoicesinit() {
WMCLASS="${1:-$(xprop -id $(xdotool getactivewindow) | grep WM_CLASS | cut -d ' ' -f3-)}"
# Default
CHOICES="$(echo "
Push window tag → ^ 0 ^ sxmo_lowpowermode.sh
Tag focus → ^ 0 ^ sxmo_lowpowermode.sh
Applications ^ 0 ^ sxmo_appmenu.sh applications
Volume ↑ ^ 1 ^ sxmo_vol.sh up
Volume ↓ ^ 1 ^ sxmo_vol.sh down
Brightesss ↑ ^ 1 ^ sxmo_brightness.sh up
Brightness ↓ ^ 1 ^ sxmo_brightness.sh down
Wifi ^ 0 ^ st -e "nmtui"
Rotate ^ 1 ^ rotate
Logout ^ 0 ^ pkill -9 dwm
Close Menu ^ 0 ^ quit
")" && WINNAME=sys
echo $WMCLASS | grep -i "applications" && CHOICES="$(echo "
Surf ^ 0 ^ surf
NetSurf ^ 0 ^ netsurf
St ^ 0 ^ st
Firefox ^ 0 ^ firefox
Foxtrotgps ^ 0 ^ foxtrotgps
Close Menu ^ 0 ^ quit
")" && WINNAME=Apps
echo $WMCLASS | grep -i "mpv" && CHOICES="$(echo "
Pause ^ 0 ^ key space
")" && WINNAME=Mpv
# St
echo $WMCLASS | grep -i "st-256color" && CHOICES="$(echo "
Pastecomplete ^ 0 ^ key Ctrl+Shift+u
Paste ^ 0 ^ key Ctrl+Shift+v
Pipe Data ^ 0 ^
Zoom + ^ 1 ^ key Ctrl+Shift+Prior
Zoom - ^ 1 ^ key Ctrl+Shift+Next
Scroll ↑ ^ 1 ^ key Shift+Prior
Scroll ↓ ^ 1 ^ key Shift+Next
Hotkeys ^ 0 ^ sxmo_appmenu.sh sthotkeys
Close Menu ^ 0 ^ quit
")" && WINNAME=st
# 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- ^ 0 ^ key Ctrl+L
Close Menu ^ 0 ^ quit
")" && WINNAME=st
# 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 Ctrl+space
Scroll ↓ ^ 1 ^ key Ctrl+b
JS Toggle ^ 1 ^ key Ctrl+Shift+s
Search ^ 1 ^ key Ctrl+f
History ← ^ 1 ^ key Ctrl+h
History → ^ 1 ^ key Ctrl+l
Close Menu ^ 0 ^ quit
")" && WINNAME=surf
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
Close Menu ^ 0 ^ quit
")" && WINNAME=netsurf
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
Gmaps Transfer ^ 0 ^ key o
Copy Cords ^ 0 ^ key o
Close Menu ^ 0 ^ quit
")" && WINNAME=gps
}
rotate() {
xrandr | grep primary | cut -d' ' -f 5 | grep right && xrandr -o normal || xrandr -o right
}
key() {
xdotool windowactivate $WIN
xdotool key --clearmodifiers $1
#--window $WIN
}
quit() {
xset r off
exit 0
}
boot() {
DMENUIDX=0
PICKED=""
xset r on
pgrep -f sxmo_appmenu.sh | grep -Ev "^${$}$" | xargs kill -9
pkill -9 dmenu
}
mainloop() {
while :
do
PICKED=$(
echo "$CHOICES" |
xargs -0 echo |
cut -d'^' -f1 |
sed '/^[[:space:]]*$/d' |
awk '{$1=$1};1' |
dmenu -idx $DMENUIDX -l 10 -c -fn "Terminus-30" -p "$WINNAME"
)
LOOP=$(echo "$CHOICES" | grep "$PICKED" | cut -d '^' -f2)
CMD=$(echo "$CHOICES" | grep "$PICKED" | cut -d '^' -f3)
DMENUIDX=$(echo $(echo "$CHOICES" | grep -n "$PICKED" | cut -d ':' -f1) - 1 | bc)
eval $CMD
echo $LOOP | grep 1 || quit
done
}
boot
programchoicesinit $@
mainloop

4
scripts/sxmo_blinkled.sh Executable file
View file

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

25
scripts/sxmo_brightness.sh Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env sh
MAX=10
MIN=2
setdelta() {
sxmo_setpinebacklight $(
cat /sys/class/backlight/backlight/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_notify.sh 200 "Backlight $(cat /sys/class/backlight/backlight/brightness)/10"
}
up() {
setdelta "+1"
}
down() {
setdelta "-1"
}
$1 $2

33
scripts/sxmo_command.sh Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env sh
power_1() {
pgrep -f sxmo_appmenu.sh || sxmo_keyboard.sh
}
power_2() {
st
}
power_3() {
surf
}
voldown_1() {
pgrep -f sxmo_appmenu.sh && xdotool key Control+n || xdotool key Alt+Ctrl+period
}
voldown_2() {
xdotool key Alt+Shift+c
}
voldown_3() {
xdotool key Alt+Return
}
volup_1() {
pgrep -f sxmo_appmenu.sh && xdotool key Control+p || sxmo_appmenu.sh
}
volup_2() {
echo nop
}
volup_3() {
echo nop
}
$@

6
scripts/sxmo_dmenu_with_kb.sh Executable file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env sh
sxmo_keyboard.sh on &
OUTPUT="$(cat | dmenu -t $@)"
sxmo_keyboard.sh off
echo "$OUTPUT"

5
scripts/sxmo_edit_screen.sh Executable file
View file

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

30
scripts/sxmo_keyboard.sh Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env sh
P=/tmp/KEYTOG
keyoff() {
kill -9 $(cat $P)
pgrep -f sxmo_keyboard.sh | grep -Ev "^${$}$" | xargs kill -9
pkill -9 svkbd-en
pkill -9 svkbd-symbols
rm $P
}
keyon() {
echo $$ >> $P
while :
do
svkbd-en -d
svkbd-symbols -d
done
}
if [ "$1" == "on" ]; then
[ -f $P ] && keyoff
keyon
elif [ "$1" == "off" ]; then
[ -f $P ] && keyoff
else
# Default toggle
[ -f $P ] && keyoff || keyon
fi

18
scripts/sxmo_lowpowermode.sh Executable file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env sh
TOUCHSCREENID=$(
xinput |
grep -i touchscreen |
grep pointer |
grep -oE 'id=[0-9]+' |
cut -d= -f2
)
xinput disable $TOUCHSCREENID
sxmo_setpineled blue 1
OLDB="$(cat /sys/class/backlight/backlight/brightness)"
sxmo_setpinebacklight 0
echo "Dragons?" | dmenu
sxmo_setpinebacklight $OLDB
sxmo_setpineled blue 0
xinput enable $TOUCHSCREENID

15
scripts/sxmo_moveresize.sh Executable file
View file

@ -0,0 +1,15 @@
move() {
xdotool keydown Alt
echo "Move done?" | dmenu
xdotool keyup Alt
}
resize() {
xdotool keydown Alt
xdotool mousedown 3
echo "Resize done?" | dmenu
xdotool keyup Alt
xdotool mouseup 3
}
$@

12
scripts/sxmo_notify.sh Executable file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env sh
HEIGHT=30
W=$1
FULLW=$(
xdpyinfo |
grep 'dimensions' |
egrep -o "[0-9]+x[0-9]+ pixels" |
sed "s/x.*//"
)
OFFX=$(echo $FULLW - $W - 2 | bc)
sh -c "echo $2 | dzen2 -p 2 -h $HEIGHT -x $OFFX -y 30" &

16
scripts/sxmo_pastecomplete.sh Executable file
View file

@ -0,0 +1,16 @@
#!/usr/bin/env sh
sxmo_keyboard.sh on &
cat |\
grep -Eo '\\S+' |\
tr -d '[:blank:]' |\
sort |\
uniq |\
dmenu -p Type -l 10 -i -c -fn Terminus-20
sxmo_keyboard.sh off
if [[ "$RESULT" = "Close Menu" ]]; then
else
xargs -I CC xdotool type "$RESULT"
fi

28
scripts/sxmo_statusbar.sh Executable file
View file

@ -0,0 +1,28 @@
#!/usr/bin/env sh
UPDATEFILE=/tmp/sxmo_bar
touch $UPDATEFILE
while :
do
PCT=$(cat /sys/class/power_supply/axp20x-battery/capacity)
BATSTATUS=$(
cat /sys/class/power_supply/axp20x-battery/status |
cut -b0
)
VOL=$(
amixer sget Headphone |
grep -oE '([0-9]+)%' |
tr -d ' %' |
awk '{ s += $1; c++ } END { print s/c }' |
xargs printf %.0f
)
TIME=$(date +%R)
BAR=" V${VOL} ${BATSTATUS}${PCT}% ${TIME}"
xsetroot -name "$BAR"
inotifywait -e MODIFY $UPDATEFILE & sleep 5 & wait -n
pgrep -P $$ | xargs kill -9
done

76
scripts/sxmo_surf_linkselect.sh Executable file
View file

@ -0,0 +1,76 @@
#!/usr/bin/env sh
# surf_linkselect.sh:
# Usage: curl somesite.com | surf_linkselect [SURFWINDOWID] [PROMPT]
# Deps: xmllint, dmenu
# Info:
# Designed to be used w/ surf externalpipe patch. Enables keyboard-only
# link selection via dmenu. Given HTML stdin, extracts links one per line
# Selected link is normalized based on current URI and printed to STDOUT.
# Pipe the result to a new surf or xprop _SURF_URI accordingly.
SURF_WINDOW="${1:-$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')}"
DMENU_PROMPT="${2:-Link}"
function 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;
match($0, /\<[ ]*[aA][^>]* [hH][rR][eE][fF]=["]([^"]+)["]/, linkextract);
$0 = linkextract[1];
gsub(/^[ \t]+/,"");
gsub(/[ \t]+$/,"");
gsub("[ ]", "%20");
link = $0;
if (link != "") {
print title ": " link;
}
}'
}
function 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;
}
}'
}
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

42
scripts/sxmo_urlhandler.sh Executable file
View file

@ -0,0 +1,42 @@
#!/usr/bin/env sh
# URL test passed from $1
URL=${1:-$URL}
# 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
# 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
COMMAND=$(
echo "
w3m URL
mpv -v URL
mpv -v --ytdl-format='[height<420]' URL
firefox -new-window URL
netsurf URL
surf URL
echo URL | xclip -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 -p "Pipe URL" -c -l 10
)
[[ -z "$COMMAND" ]] && exit 1
RUN=$(echo $URL | xargs -IURL echo "$COMMAND")
st -e sh -c "$RUN"

12
scripts/sxmo_vol.sh Executable file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env sh
incvol() {
amixer set Headphone 1+
echo 1 > /tmp/sxmo_bar
}
decvol() {
amixer set Headphone 1-
echo 1 > /tmp/sxmo_bar
}
echo $1 | grep up && echo 1 > /tmp/sxmo_bar && incvol
echo $1 | grep down && echo 1 > /tmp/sxmo_bar && decvol

12
scripts/sxmo_xinit.sh Executable file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env sh
source /etc/profile
which $TERM || export TERM=st
which $BROWSER || export BROWSER=surf
xsetroot -mod 3 2 -fg '#000000' -bg '#888888'
conky -c /usr/share/sxmo/conky.conf -d
sxmo_statusbar.sh &
xset r off
alsactl --file /usr/share/sxmo/default_alsa_sound.conf restore
exec dbus-run-session dwm 2> ~/.dwm.log