feature: Add automated colorscheme switching to Ghostty, refactor
watchman_tmux into generic utility function.
This commit is contained in:
parent
6521dedbaa
commit
a15f2238aa
7 changed files with 164 additions and 68 deletions
39
nix/home/common/watchman_colorsync_services.nix
Normal file
39
nix/home/common/watchman_colorsync_services.nix
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
isLinux,
|
||||
isDarwin,
|
||||
...
|
||||
}:
|
||||
let
|
||||
utils = import ../../utils.nix;
|
||||
in
|
||||
lib.mkMerge [
|
||||
(utils.mkWatchmanTrigger {
|
||||
inherit
|
||||
pkgs
|
||||
lib
|
||||
config
|
||||
isLinux
|
||||
isDarwin
|
||||
;
|
||||
name = "ghostty";
|
||||
triggerName = "ghostty_theme";
|
||||
scriptPath = "$HOME/.config/ghostty/ghostty-change-theme.sh";
|
||||
description = "Register watchman trigger for Ghostty themes.";
|
||||
})
|
||||
(utils.mkWatchmanTrigger {
|
||||
inherit
|
||||
pkgs
|
||||
lib
|
||||
config
|
||||
isLinux
|
||||
isDarwin
|
||||
;
|
||||
name = "tmux";
|
||||
triggerName = "tmux_statusbar_color";
|
||||
scriptPath = "$HOME/.config/tmux/tmux-statusbar-color.sh";
|
||||
description = "Register watchman trigger for Tmux statusbar colors.";
|
||||
})
|
||||
]
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
isLinux,
|
||||
isDarwin,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
scriptPkg = pkgs.writeShellScriptBin "tmux-watchman-statuscolor" ''
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$HOME/.local/state/colorsync"
|
||||
TRIGGER_NAME="tmux_statusbar_color"
|
||||
SCRIPT="$HOME/.config/tmux/tmux-statusbar-color.sh"
|
||||
WATCHMAN="${pkgs.watchman}/bin/watchman"
|
||||
|
||||
"$WATCHMAN" -- watch-project "$ROOT" >/dev/null
|
||||
"$WATCHMAN" -- trigger-del "$ROOT" "$TRIGGER_NAME" >/dev/null 2>&1 || true
|
||||
"$WATCHMAN" -- trigger "$ROOT" "$TRIGGER_NAME" current -- bash "$SCRIPT"
|
||||
'';
|
||||
|
||||
pathForService = lib.makeBinPath [
|
||||
pkgs.watchman
|
||||
pkgs.bash
|
||||
pkgs.coreutils
|
||||
];
|
||||
|
||||
linuxAttrs = lib.optionalAttrs isLinux {
|
||||
systemd.user.startServices = "sd-switch";
|
||||
systemd.user.services.tmux-watchman = {
|
||||
Unit = {
|
||||
Description = "Register watchman trigger for tmux statusbar color";
|
||||
After = [ "graphical-session.target" ];
|
||||
};
|
||||
Service = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${scriptPkg}/bin/tmux-watchman-statuscolor";
|
||||
Environment = [ "PATH=${pathForService}" ];
|
||||
StandardOutput = "journal";
|
||||
StandardError = "journal";
|
||||
};
|
||||
Install = {
|
||||
WantedBy = [ "default.target" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
darwinAttrs = lib.optionalAttrs isDarwin {
|
||||
launchd.agents.tmux-watchman = {
|
||||
enable = true;
|
||||
config = {
|
||||
ProgramArguments = [ "${scriptPkg}/bin/tmux-watchman-statuscolor" ];
|
||||
RunAtLoad = true;
|
||||
KeepAlive = false;
|
||||
EnvironmentVariables = {
|
||||
PATH = pathForService;
|
||||
};
|
||||
StandardOutPath = "${config.home.homeDirectory}/Library/Logs/tmux-watchman.log";
|
||||
StandardErrorPath = "${config.home.homeDirectory}/Library/Logs/tmux-watchman.err";
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
linuxAttrs // darwinAttrs
|
||||
|
|
@ -67,7 +67,7 @@ let
|
|||
in
|
||||
{
|
||||
imports = [
|
||||
./common/watchman_tmux.nix
|
||||
./common/watchman_colorsync_services.nix
|
||||
./common/firefox.nix
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -46,4 +46,86 @@ rec {
|
|||
${pkgs.mkalias}/bin/mkalias "$src" "${outputDir}/$app_name"
|
||||
done
|
||||
'';
|
||||
|
||||
mkWatchmanTrigger =
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
isLinux,
|
||||
isDarwin,
|
||||
|
||||
name,
|
||||
triggerName,
|
||||
scriptPath,
|
||||
|
||||
root ? "$HOME/.local/state/colorsync",
|
||||
description ? "Register watchman trigger for ${name}.",
|
||||
watchExpr ? "current",
|
||||
}:
|
||||
let
|
||||
serviceName = "${name}-watchman";
|
||||
# e.g. tmux-watchman-statuscolor, ghostty-watchman-theme
|
||||
binName =
|
||||
let
|
||||
trig = lib.replaceStrings [ "_" ] [ "-" ] triggerName;
|
||||
in
|
||||
"${serviceName}-${trig}";
|
||||
|
||||
scriptPkg = pkgs.writeShellScriptBin binName ''
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="${root}"
|
||||
TRIGGER_NAME="${triggerName}"
|
||||
SCRIPT="${scriptPath}"
|
||||
WATCHMAN="${pkgs.watchman}/bin/watchman"
|
||||
|
||||
"$WATCHMAN" -- watch-project "$ROOT" >/dev/null
|
||||
"$WATCHMAN" -- trigger-del "$ROOT" "$TRIGGER_NAME" >/dev/null 2>&1 || true
|
||||
"$WATCHMAN" -- trigger "$ROOT" "$TRIGGER_NAME" ${watchExpr} -- bash "$SCRIPT"
|
||||
'';
|
||||
|
||||
pathForService = lib.makeBinPath [
|
||||
pkgs.watchman
|
||||
pkgs.bash
|
||||
pkgs.coreutils
|
||||
];
|
||||
|
||||
linuxAttrs = lib.optionalAttrs isLinux {
|
||||
systemd.user.startServices = "sd-switch";
|
||||
systemd.user.services."${serviceName}" = {
|
||||
Unit = {
|
||||
Description = description;
|
||||
After = [ "graphical-session.target" ];
|
||||
};
|
||||
Service = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${scriptPkg}/bin/${binName}";
|
||||
Environment = [ "PATH=${pathForService}" ];
|
||||
StandardOutput = "journal";
|
||||
StandardError = "journal";
|
||||
};
|
||||
Install = {
|
||||
WantedBy = [ "default.target" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
darwinAttrs = lib.optionalAttrs isDarwin {
|
||||
launchd.agents."${serviceName}" = {
|
||||
enable = true;
|
||||
config = {
|
||||
ProgramArguments = [ "${scriptPkg}/bin/${binName}" ];
|
||||
RunAtLoad = true;
|
||||
KeepAlive = false;
|
||||
EnvironmentVariables = {
|
||||
PATH = pathForService;
|
||||
};
|
||||
StandardOutPath = "${config.home.homeDirectory}/Library/Logs/${serviceName}.log";
|
||||
StandardErrorPath = "${config.home.homeDirectory}/Library/Logs/${serviceName}.err";
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
linuxAttrs // darwinAttrs;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue