2023-07-04 20:24:29 +02:00
|
|
|
#!/usr/bin/env nu
|
|
|
|
|
|
|
|
module ipc {
|
|
|
|
|
|
|
|
def ipcCmd [] {
|
|
|
|
if (is-sway) {
|
|
|
|
"swaymsg"
|
|
|
|
} else if (is-i3) {
|
|
|
|
"i3-msg"
|
|
|
|
} else {
|
|
|
|
error make { msg: "This script only supports sway or i3" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def is-sway [] {
|
|
|
|
("SWAYSOCK" in $env)
|
|
|
|
}
|
|
|
|
|
|
|
|
def is-i3 [] {
|
|
|
|
("I3SOCK" in $env)
|
|
|
|
}
|
|
|
|
|
|
|
|
export def ipc-cmd [--raw, ...parameters: string] {
|
2024-03-11 17:53:12 +01:00
|
|
|
let result = (run-external --redirect-stdout (ipcCmd) ...$parameters)
|
2023-07-04 20:24:29 +02:00
|
|
|
if $raw {
|
|
|
|
$result
|
|
|
|
} else {
|
|
|
|
$result | from json
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
use ipc ipc-cmd
|
|
|
|
|
|
|
|
def workspaces [] {
|
|
|
|
let workspaces = (ipc-cmd "-t" "get_workspaces" | select id name focused urgent visible)
|
|
|
|
let mode = (ipc-cmd "-t" "get_binding_state")
|
|
|
|
let focused_title = ((ipc-cmd --raw "-t" "get_tree") | jaq -r '.. | (.nodes? // empty)[] | select(.focused) | {name}' | from json)
|
|
|
|
|
|
|
|
{ workspaces: $workspaces, mode: $mode.name, title: $focused_title.name }
|
|
|
|
}
|
|
|
|
|
|
|
|
def main [] {
|
|
|
|
print (workspaces | to json -r)
|
|
|
|
loop {
|
|
|
|
ipc-cmd --raw '-t' 'subscribe' '["workspace","window","mode"]' out+err> /dev/null
|
|
|
|
try {
|
|
|
|
print (workspaces | to json -r)
|
|
|
|
}
|
|
|
|
}
|
2024-03-11 17:53:12 +01:00
|
|
|
}
|