Open zeltak opened 7 years ago
I was curious how I could implement this, so I tried to get something working with rofi
and came up with the following. It unfortunately does not work for your Left
and Right
cases, so I removed them from the script.
#!/usr/bin/env bash
keys=$(echo 't,c,3,4,5,r,a,z,e,w,p,l' | tr ',' $'\n')
cmds=$(cat <<'EOF'
clerk --add track
clerk
clerk --rate instant 6
clerk --rate instant 8
clerk --rate instant 10
clerk --rate track
clerk --add album
clerk --random album
/home/zeltak/bin/mpdaddrated.sh
clerk --rate load
clerk --queue show
clerk --add latest
EOF
)
d=$(paste <(echo "$keys") <(echo "$cmds") | column -t -s $'\t' | rofi -dmenu -p 'key:' -format d -auto-select -matching regex -filter '^')
$(echo "$cmds" | sed "${d}q;d")
Does someone know of a way to get rofi
to filter lines other than by their contents? I hoped a custom modi could do this, but the modi script is not responsible for filtering as far as I know. In this script I worked around it by leveraging regex matching and prefilling the filter with ^
.
Another approach which would not require such workarounds and would allow for Left
and Right
is to have another sxhkdrc
that is used instead of your default one the moment you press super + c
. In addition to switching your sxhkdrc
you would also show the cheat sheet, probably with something different than rofi
. The other sxhkdrc
could be as simple as your original snippet without the super + c
prefix:
{Left,Right,t,c,3,4,5,r,a,z,e,w,p,l}
{ \
mpc seek -10, \
mpc seek +10, \
clerk --add track, \
clerk, \
clerk --rate instant 6, \
clerk --rate instant 8, \
clerk --rate instant 10, \
clerk --rate track, \
clerk --add album, \
clerk --random album, \
/home/zeltak/bin/mpdaddrated.sh, \
clerk --rate load, \
clerk --queue show, \
clerk --add latest \
}
thx for this. any progress with integrating the left/right options?
I do not really know of an easy and clean solution, but here is one of many hacky solutions you could think of:
#!/usr/bin/env bash
keys=$(echo '<,>,t,c,3,4,5,r,a,z,e,w,p,l' | tr ',' $'\n')
cmds=$(cat <<'EOF'
mpc seek -10
mpc seek +10
clerk --add track
clerk
clerk --rate instant 6
clerk --rate instant 8
clerk --rate instant 10
clerk --rate track
clerk --add album
clerk --random album
/home/zeltak/bin/mpdaddrated.sh
clerk --rate load
clerk --queue show
clerk --add latest
EOF
)
xinput --test-xi2 --root $(xinput --list | sed -n -e 's/.*id=\([0-9]\{1,\}\).*master keyboard.*/\1/p') | \
sed -un -e 's/EVENT type \([0-9]\{1,\}\).*/\1/p' -e 's/.*detail: \([0-9]\{1,\}\)/\1/p' | \
while read -r line; do
# If `n` is undefined it also equals 0.
if [[ $n -eq 0 ]]; then
n=1
# 13 key press
# 14 key release
et=$line
else
n=0
# 113 Left
# 114 Right
ec=$line
if [[ $et -eq 14 && $ec -eq 113 ]]; then
# First undo the effect of moving the cursor to the left.
xdotool key Right
xdotool key less
exit 0
fi
if [[ $et -eq 14 && $ec -eq 114 ]]; then
xdotool key greater
exit 0
fi
fi
done &
d=$(paste <(echo "$keys") <(echo "$cmds") | column -t -s $'\t' | rofi -dmenu -p 'key:' -format d -auto-select -matching regex -filter '^')
kill $(jobs -p)
$(echo "$cmds" | sed "${d}q;d")
It uses xinput
to watch for left and right arrow key releases and then uses xdotool
to send keys to rofi
that can be handled by my regex filter trick. I used the greater than and less than signs, but you could of course change that if you want.
seems to work great!
thx so much :)
wonder if something like this (visual queues) will make it into sxhkd in the future?
Providing visual hints would be amazing.
The best source of inspiration I can think of is Emacs Hydra (example video).
Hi!
suppose i have this command
would be great if when i press
supet+c
i could trigger a visual cue with all possible completions. is there anyway to do that? perhaps pipe text to rofi/dunst/linbotify?thx!
Z