Open keilmillerjr opened 5 months ago
the rofi examples were provided by @abs3ntdev, maybe they are able to provide their configs
Here is a quick script i wrote up. Uses wofi, but should be exactly the same for rofi
# Format JSON proper;y
JSON=$(hyprkeys --from-ctl --json | jq -r --slurp "[.[]][0]");
USER_SELECTED=$(echo $JSON | jq -r '.[] | "\(.mods) \(.key) \(.dispatcher) \(.arg)"' | wofi --dmenu -p 'Keybinds' --define "dmenu-print_line_num=true");
if [ -z "$USER_SELECTED" ]; then
exit 0;
fi
EVENT=$(echo $JSON | jq -r "[.[]] | .[$USER_SELECTED]" | jq -r '"\(.dispatcher) \(.arg)"');
hyprctl dispatch "$EVENT";
It's not the prettiest but it works well enough for me!
You could well enough do this with just hyprctl, but using JSON with hyprkeys does make it a lot nicer.
One issue though, using --from-ctl means that we have to add this bullshit jq -r --slurp "[.[]][0]")
as it always outputs twice for me.
Might make an issue, unless that is intended @NotAShelf?
Here is a quick script i wrote up. Uses wofi, but should be exactly the same for rofi
# Format JSON proper;y JSON=$(hyprkeys --from-ctl --json | jq -r --slurp "[.[]][0]"); USER_SELECTED=$(echo $JSON | jq -r '.[] | "\(.mods) \(.key) \(.dispatcher) \(.arg)"' | wofi --dmenu -p 'Keybinds' --define "dmenu-print_line_num=true"); if [ -z "$USER_SELECTED" ]; then exit 0; fi EVENT=$(echo $JSON | jq -r "[.[]] | .[$USER_SELECTED]" | jq -r '"\(.dispatcher) \(.arg)"'); hyprctl dispatch "$EVENT";
It's not the prettiest but it works well enough for me!
Thanks for the snippet, it didn't quite work 1:1 with rofi because --define "dmenu-print_line_num=true"
isn't supported, so I adapted it accordingly:
# Format JSON proper;y
JSON=$(hyprkeys --from-ctl --json | jq -r --slurp "[.[]][0]");
USER_SELECTED=$(echo $JSON | jq -r 'range(0, length) as $i | "\($i) \(.[$i].mods) \(.[$i].key) \(.[$i].dispatcher) \(.[$i].arg)"' | rofi -dmenu -p 'Keybinds' | awk -F ' ' '{print $1}')
if [ -z "$USER_SELECTED" ]; then
exit 0;
fi
EVENT=$(echo $JSON | jq -r "[.[]] | .[$USER_SELECTED]" | jq -r '"\(.dispatcher) \(.arg)"');
hyprctl dispatch "$EVENT";
Ah yeh, that makes sense.
That's just a wofi option so that it returns an index instead of the actual data.
You could strip down the data, but I thought that was a little over engineered!
@fiskhest
Just figured out you can output raw instead, which doesn't return the extra piece of json when using --from-ctl
So we can just do
JSON=$(hyprkeys --from-ctl --raw)
Readme shows an image of hyprkeys being used with a rofi script. Is there a source for the example?