From 5af8007804f1328208786a4537fe0bf3b0f3f1f3 Mon Sep 17 00:00:00 2001 From: Johannes Kresner Date: Fri, 31 Jul 2026 00:28:11 +0200 Subject: [PATCH] feat: add herdr & pi auto theme --- config/herdr/config.toml | 18 +++++++++ config/nushell/config.nu | 2 +- config/nushell/scripts/commands.nu | 12 ++++++ home.nix | 1 + pi/agent/settings.json | 5 ++- pi/extensions/auto-theme.ts | 65 ++++++++++++++++++++++++++++++ 6 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 config/herdr/config.toml create mode 100644 pi/extensions/auto-theme.ts diff --git a/config/herdr/config.toml b/config/herdr/config.toml new file mode 100644 index 0000000..123513b --- /dev/null +++ b/config/herdr/config.toml @@ -0,0 +1,18 @@ +[theme] +auto_switch = true +dark_name = "catppuccin" +light_name = "catppuccin-latte" + +[keys] +# Prefix key +prefix = "ctrl+b" + +# Direct pane navigation (bypasses prefix) +focus_pane_left = "alt+h" +focus_pane_down = "alt+j" +focus_pane_up = "alt+k" +focus_pane_right = "alt+l" + +# Direct pane creation (bypasses prefix) +split_vertical = "alt+v" +split_horizontal = "alt+s" diff --git a/config/nushell/config.nu b/config/nushell/config.nu index 1182bd2..38f6db9 100644 --- a/config/nushell/config.nu +++ b/config/nushell/config.nu @@ -114,7 +114,7 @@ overlay use scripts/alias-finder.nu source scripts/commands.nu -source ~/.local/share/nushell/vendor/autoload/wt.nu +#source ~/.local/share/nushell/vendor/autoload/wt.nu #---------------- # Custom Commands diff --git a/config/nushell/scripts/commands.nu b/config/nushell/scripts/commands.nu index 6a5ebf7..1e1e86d 100644 --- a/config/nushell/scripts/commands.nu +++ b/config/nushell/scripts/commands.nu @@ -55,6 +55,18 @@ def --env zj [path?: string] { zellij attach -c $session_name } +# hd: "Smart Herdr" +# 1. If argument provided: cd there, then open herdr +# 2. If no argument: open herdr in current dir +def --env hd [path?: string] { + if ($path != null) { + cd $path + } + let session_name = ($env.PWD | path basename) + + herdr --session $session_name +} + def man [topic: string] { ^man $topic | bat -l man -p } diff --git a/home.nix b/home.nix index ea0c4b4..9877a30 100644 --- a/home.nix +++ b/home.nix @@ -19,6 +19,7 @@ fastfetch atuin zellij + herdr unp carapace bun diff --git a/pi/agent/settings.json b/pi/agent/settings.json index 971a941..9ebe247 100644 --- a/pi/agent/settings.json +++ b/pi/agent/settings.json @@ -2,6 +2,9 @@ "lastChangelogVersion": "0.82.0", "defaultProvider": "openai-codex", "defaultModel": "gpt-5.5", + "extensions": [ + "../extensions" + ], "packages": [ "npm:pi-antigravity", "npm:pi-catppuccin-tui", @@ -19,7 +22,7 @@ ], "theme": "catppuccin-tui-latte", "hideThinkingBlock": true, - "quiteStartup": true, + "quietStartup": true, "enableInstallTelemetry": false, "powerline": "full" } diff --git a/pi/extensions/auto-theme.ts b/pi/extensions/auto-theme.ts new file mode 100644 index 0000000..bb8ff55 --- /dev/null +++ b/pi/extensions/auto-theme.ts @@ -0,0 +1,65 @@ +// @ts-nocheck +import { exec } from "node:child_process"; +import { promisify } from "node:util"; +import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; + +const execAsync = promisify(exec); + +async function checkTheme(): Promise<{ dark: boolean; error?: string }> { + try { + if (process.platform === "darwin") { + const { stdout } = await execAsync( + "osascript -e 'tell application \"System Events\" to tell appearance preferences to return dark mode'", + ); + return { dark: stdout.trim() === "true" }; + } else if (process.platform === "linux") { + const { stdout } = await execAsync( + "dbus-send --session --print-reply --dest=org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings.Read string:'org.freedesktop.appearance' string:'color-scheme'", + ); + // 1 is Dark, 2 is Light, 0 is Default + return { dark: stdout.includes("uint32 1") }; + } + return { dark: true, error: "Unsupported OS" }; + } catch (e: any) { + return { dark: true, error: e.message.split("\n")[0] }; // First line of error + } +} + +export default function (pi: ExtensionAPI) { + let intervalId: ReturnType | null = null; + + const updateTheme = async (ctx: any, currentTheme: string) => { + const res = await checkTheme(); + const newTheme = res.dark ? "catppuccin-tui-mocha" : "catppuccin-tui-latte"; + + if (res.error) { + ctx.ui.setStatus( + "auto-theme", + ctx.ui.theme.fg("error", `theme err: ${res.error}`), + ); + } else { + ctx.ui.setStatus("auto-theme", ctx.ui.theme.fg("muted", "theme auto")); + } + + if (newTheme !== currentTheme) { + ctx.ui.setTheme(newTheme); + } + return newTheme; + }; + + pi.on("session_start", async (_event, ctx) => { + let currentTheme = ""; + currentTheme = await updateTheme(ctx, currentTheme); + + intervalId = setInterval(async () => { + currentTheme = await updateTheme(ctx, currentTheme); + }, 2000); + }); + + pi.on("session_shutdown", () => { + if (intervalId) { + clearInterval(intervalId); + intervalId = null; + } + }); +}