refactor: use active-window utility in scripts

Migrates quick-zeal and spawn-term from compositor-specific APIs
(hyprctl, kdotool, niri msg) to the unified active-window utility.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Christopher Mühl 2026-02-28 01:25:46 +01:00
parent 9e49bd830d
commit f49a9c8019
No known key found for this signature in database
GPG key ID: 925AC7D69955293F
3 changed files with 9 additions and 19 deletions

View file

@ -1,5 +1,6 @@
{pkgs, ...}:
pkgs.writeShellApplication {
name = "quick-zeal";
runtimeInputs = [pkgs.harbor.active-window pkgs.jq];
text = builtins.readFile ./quick-zeal;
}

View file

@ -6,13 +6,14 @@ extract_major_version() {
}
# Detects the focused window and checks if it's Kitty
ACTIVE_WINDOW=$(hyprctl activewindow -j | jq -r '.class')
WINDOW=$(active-window)
ACTIVE_WINDOW=$(printf '%s' "$WINDOW" | jq -r '.class // empty')
PID=$(printf '%s' "$WINDOW" | jq -r '.pid // empty')
# Check if the focused window is a Kitty terminal and if it's in a Git repository.
# If so, determine the project type and open Zeal with the appropriate argument
zeal_argument=""
if [[ $ACTIVE_WINDOW == "kitty" ]]; then
PID=$(hyprctl activewindow -j | jq -r '.pid')
CHILD_PID=$(pgrep -P "$PID" | tail -1)
SHELL_CWD=$(readlink -f "/proc/${CHILD_PID}/cwd")

View file

@ -1,25 +1,13 @@
{pkgs, ...}:
pkgs.writeNushellApplication {
name = "spawn-term";
runtimeInputs = with pkgs; [kdotool];
runtimeInputs = [pkgs.harbor.active-window];
text = ''
let compositor = $env.XDG_CURRENT_DESKTOP? | default ""
let window_info = if ($compositor | str contains "niri") {
let focused_window = (niri msg --json focused-window | from json | get id?)
if ($focused_window | is-empty) {
{ is_kitty: false, pid: null }
} else {
let info = (niri msg --json windows | from json | where id == $focused_window | first)
{ is_kitty: ($info.app_id? == "kitty"), pid: $info.pid? }
}
} else {
let focused_window = (kdotool getactivewindow)
{
is_kitty: ((kdotool getwindowclassname $focused_window) == "kitty"),
pid: (kdotool getwindowpid $focused_window | into int)
}
let window = (active-window | from json)
let window_info = {
is_kitty: ($window.class? == "kitty"),
pid: $window.pid?
}
if $window_info.is_kitty {