Add a module I forked from polybar-scripts
I rewrote the info-hackspeed script. It should be a tad more energy efficient now (just laptop things), you can also choose between cpm and wpm, and the file is stored in RAM (in /tmp) instead of on disk.
This commit is contained in:
parent
e374ee9348
commit
2d98967aa7
2 changed files with 41 additions and 0 deletions
|
@ -390,6 +390,11 @@ menu-2-0-exec = sudo poweroff
|
|||
menu-2-1 = cancel
|
||||
menu-2-1-exec = menu-open-0
|
||||
|
||||
[module/info-hackspeed]
|
||||
type = custom/script
|
||||
exec = ~/.config/polybar/info-hackspeed.sh
|
||||
tail = true
|
||||
|
||||
[settings]
|
||||
screenchange-reload = true
|
||||
;compositing-background = xor
|
||||
|
|
36
polybar/info-hackspeed.sh
Executable file
36
polybar/info-hackspeed.sh
Executable file
|
@ -0,0 +1,36 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Only count keys that satisfy this condition. $3 is the key index
|
||||
# Use `xinput test "AT Translated Set 2 keyboard"` to find out key indices
|
||||
CONDITION='($3 >= 24 && $3 <= 33) || ($3 >= 37 && $3 <= 54) || ($3 >= 52 && $3 <= 57)'
|
||||
|
||||
# cpm: characters per minute
|
||||
# wpm: words per minute (1 word = 5 characters)
|
||||
METRIC=wpm
|
||||
|
||||
FORMAT=" %d $METRIC\n"
|
||||
|
||||
|
||||
case "$METRIC" in
|
||||
wpm) factor=3; ;;
|
||||
cpm) factor=1; ;;
|
||||
*) echo "Unsupported metric \"$METRIC\""; exit 1; ;;
|
||||
esac
|
||||
|
||||
hackspeed_cache="$(mktemp -p '' hackspeed_cache.XXXXX)"
|
||||
trap 'rm "$hackspeed_cache"' EXIT
|
||||
|
||||
# Write a dot to our cache for each key press
|
||||
printf '' > "$hackspeed_cache"
|
||||
xinput test "AT Translated Set 2 keyboard" | \
|
||||
stdbuf -o0 awk '$1 == "key" && $2 == "press" && ('"$CONDITION"') {printf "."}' >> "$hackspeed_cache" &
|
||||
|
||||
while true; do
|
||||
lines=$(stat --format %s "$hackspeed_cache")
|
||||
value=$(($lines * $factor / 5))
|
||||
|
||||
printf '' > "$hackspeed_cache"
|
||||
printf "$FORMAT" "$value"
|
||||
|
||||
sleep 20
|
||||
done
|
Loading…
Reference in a new issue