Hyprland
Hyprland copied to clipboard
separation for different outputs from multiple socket commands in batch
Description
normally you can get output from commands like this:
❯ hyprctl --batch "j/version"
{
"branch": "",
"commit": "",
"dirty": true,
"commit_message": "",
"commit_date": "",
"tag": "",
"commits": "",
"flags": []
}
but if you are running multiple commands, there is no delimiter to programmatically separate the different outputs:
❯ hyprctl --batch "j/cursorpos;j/version"
{
"x": 1504,
"y": 490
}
{
"branch": "",
"commit": "",
"dirty": true,
"commit_message": "",
"commit_date": "",
"tag": "",
"commits": "",
"flags": []
}
or
❯ hyprctl --batch "j/version;j/version"
{
"branch": "",
"commit": "",
"dirty": true,
"commit_message": "",
"commit_date": "",
"tag": "",
"commits": "",
"flags": []
}{
"branch": "",
"commit": "",
"dirty": true,
"commit_message": "",
"commit_date": "",
"tag": "",
"commits": "",
"flags": []
}
Possible solutions
- put the outputs in a JSON array
This doesn't really work since not all commands have a JSON output. So you might get something like this:
[
ok,
{
"branch": "",
"commit": "",
"dirty": true,
"commit_message": "",
"commit_date": "2024-01-01",
"tag": "",
"flags": []
}
]
- Set a delimiter.
Easiest solution but will break if one of the outputs have the delimiter. A delimiter of 3 newlines is very unlikely to appear in any output, so we can use that.