Spring
Spring

Reputation: 31

Parsing a Hyprland configuration for use in GUI?

So, I'm trying to parse a Hyprland configuration for keybindings to use in Aylur's Gtk Shell, version 2 (herein referred to as AGSv2 and Astal), using TypeScript.

What I'm trying to do is a window like this, invoked with Super+/ (from a shell we based on using AGSv1): Keyboard shortcuts window showcasing which shortcut does what (I don't have enough reputation to post images directly, the link is a CDN link from SO anyway.)

I already managed to make a oneliner to get the bind= entries from the desired configuration file:

cat ~/.config/hypr/config/keybindings/default.conf | grep "^bind.*=" | sed 's/#.*//; s/.*= //; s/[ \t]*$//'

An example output from this command is as follows:

$mainMod, 1, workspace, 1
$mainMod, 2, workspace, 2
$mainMod, 3, workspace, 3
$mainMod, 4, workspace, 4
$mainMod, 5, workspace, 5
$mainMod, 6, workspace, 6
$mainMod, 7, workspace, 7
$mainMod, 8, workspace, 8
$mainMod, 9, workspace, 9
$mainMod, 0, workspace, 10
, XF86MonBrightnessUp, exec, brightnessctl -q s +10%
, XF86MonBrightnessDown, exec, brightnessctl -q s 10%-

Here's an example file to work with:

# -----------------------------------------------------
# Key bindings
# name: "Default"
# -----------------------------------------------------

# Super key
$mainMod = SUPER # Sets "Windows" key as main modifier

# Workspaces
bind = $mainMod, 1, workspace, 1 # Switch to workspace 1
bind = $mainMod, 2, workspace, 2 # Switch to workspace 2
bind = $mainMod, 3, workspace, 3 # Switch to workspace 3
bind = $mainMod, 4, workspace, 4 # Switch to workspace 4
bind = $mainMod, 5, workspace, 5 # Switch to workspace 5
bind = $mainMod, 6, workspace, 6 # Switch to workspace 6
bind = $mainMod, 7, workspace, 7 # Switch to workspace 7
bind = $mainMod, 8, workspace, 8 # Switch to workspace 8
bind = $mainMod, 9, workspace, 9 # Switch to workspace 9
bind = $mainMod, 0, workspace, 10 # Switch to workspace (1)0

# Brightness
bind = , XF86MonBrightnessUp, exec, brightnessctl -q s +10% # Increase brightness by 10%
bind = , XF86MonBrightnessDown, exec, brightnessctl -q s 10%- # Decrease brightness by 10%

I would also much appreciate if this could be done in a way that turns this into a JQuery format, or a format that can be parsed by TypeScript, though not strictly required as I can also try and make it myself. I just need to be able to parse these into discrete shell variables so I can map these programmatically on Hyprland/AGSv2 startup.

Upvotes: 2

Views: 74

Answers (0)

Related Questions