Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

rofi #16

Open
keilmillerjr opened this issue Jan 31, 2024 · 5 comments
Open

rofi #16

keilmillerjr opened this issue Jan 31, 2024 · 5 comments

Comments

@keilmillerjr
Copy link

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

@NotAShelf
Copy link
Member

NotAShelf commented Jan 31, 2024

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

@sjcobb2022
Copy link

sjcobb2022 commented Mar 3, 2024

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
Copy link

fiskhest commented Mar 8, 2024

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
Copy link

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
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants