#/usr/bin/env nu

def main [app: string, command: string] {
  let open = niri msg --json windows | from json | where app_id == $app | get id | first;
  if open == null {
    bash -c $"($command) &"
  } else {
    niri msg action focus-window --id $open
  }
}
