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:
parent
9e49bd830d
commit
f49a9c8019
3 changed files with 9 additions and 19 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
{pkgs, ...}:
|
{pkgs, ...}:
|
||||||
pkgs.writeShellApplication {
|
pkgs.writeShellApplication {
|
||||||
name = "quick-zeal";
|
name = "quick-zeal";
|
||||||
|
runtimeInputs = [pkgs.harbor.active-window pkgs.jq];
|
||||||
text = builtins.readFile ./quick-zeal;
|
text = builtins.readFile ./quick-zeal;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,14 @@ extract_major_version() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Detects the focused window and checks if it's Kitty
|
# 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.
|
# 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
|
# If so, determine the project type and open Zeal with the appropriate argument
|
||||||
zeal_argument=""
|
zeal_argument=""
|
||||||
if [[ $ACTIVE_WINDOW == "kitty" ]]; then
|
if [[ $ACTIVE_WINDOW == "kitty" ]]; then
|
||||||
PID=$(hyprctl activewindow -j | jq -r '.pid')
|
|
||||||
CHILD_PID=$(pgrep -P "$PID" | tail -1)
|
CHILD_PID=$(pgrep -P "$PID" | tail -1)
|
||||||
|
|
||||||
SHELL_CWD=$(readlink -f "/proc/${CHILD_PID}/cwd")
|
SHELL_CWD=$(readlink -f "/proc/${CHILD_PID}/cwd")
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,13 @@
|
||||||
{pkgs, ...}:
|
{pkgs, ...}:
|
||||||
pkgs.writeNushellApplication {
|
pkgs.writeNushellApplication {
|
||||||
name = "spawn-term";
|
name = "spawn-term";
|
||||||
runtimeInputs = with pkgs; [kdotool];
|
runtimeInputs = [pkgs.harbor.active-window];
|
||||||
|
|
||||||
text = ''
|
text = ''
|
||||||
let compositor = $env.XDG_CURRENT_DESKTOP? | default ""
|
let window = (active-window | from json)
|
||||||
|
let window_info = {
|
||||||
let window_info = if ($compositor | str contains "niri") {
|
is_kitty: ($window.class? == "kitty"),
|
||||||
let focused_window = (niri msg --json focused-window | from json | get id?)
|
pid: $window.pid?
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if $window_info.is_kitty {
|
if $window_info.is_kitty {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue