hyprland-community / Hyprkeys

A simple, scriptable keybind retrieval utility for Hyprland [maintainer=none]
GNU General Public License v3.0
121 stars 6 forks source link

rofi #16

Open keilmillerjr opened 5 months ago

keilmillerjr commented 5 months ago

Readme shows an image of hyprkeys being used with a rofi script. Is there a source for the example?

NotAShelf commented 5 months ago

the rofi examples were provided by @abs3ntdev, maybe they are able to provide their configs

sjcobb2022 commented 4 months ago

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?

fiskhest commented 4 months ago

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";
sjcobb2022 commented 4 months ago

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!

sjcobb2022 commented 4 months ago

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