Rework colorsync file-watching using fswatch instead of watchman
This commit is contained in:
parent
f74c830e88
commit
de289309f7
5 changed files with 72 additions and 85 deletions
36
nix/home/common/colorsync_services.nix
Normal file
36
nix/home/common/colorsync_services.nix
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
isLinux,
|
||||||
|
isDarwin,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
utils = import ../../utils.nix;
|
||||||
|
|
||||||
|
name = "colorsync-scriptrunner";
|
||||||
|
colorsyncScriptWrapper = pkgs.writeShellScriptBin "${name}-wrapper" ''
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
echo colorsync-scriptrunner is executing
|
||||||
|
"$HOME/.config/tmux/tmux-statusbar-color.sh"
|
||||||
|
"$HOME/.config/ghostty/ghostty-change-theme.sh"
|
||||||
|
'';
|
||||||
|
root = "$HOME/.local/state/colorsync/current";
|
||||||
|
in
|
||||||
|
lib.mkMerge [
|
||||||
|
(utils.mkFswatchService {
|
||||||
|
inherit
|
||||||
|
pkgs
|
||||||
|
lib
|
||||||
|
config
|
||||||
|
isLinux
|
||||||
|
isDarwin
|
||||||
|
;
|
||||||
|
name = name;
|
||||||
|
scriptPath = "${colorsyncScriptWrapper}/bin/${name}-wrapper";
|
||||||
|
root = root;
|
||||||
|
description = "Run colorsync-scriptrunner after ${root} changes.";
|
||||||
|
})
|
||||||
|
]
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
{
|
|
||||||
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.";
|
|
||||||
})
|
|
||||||
]
|
|
||||||
|
|
@ -67,7 +67,7 @@ let
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./common/watchman_colorsync_services.nix
|
./common/colorsync_services.nix
|
||||||
./common/firefox.nix
|
./common/firefox.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -144,8 +144,8 @@ in
|
||||||
rainfrog
|
rainfrog
|
||||||
atac
|
atac
|
||||||
p7zip
|
p7zip
|
||||||
watchman
|
|
||||||
colorsync
|
colorsync
|
||||||
|
fswatch
|
||||||
];
|
];
|
||||||
|
|
||||||
file = utils.mk_symlinks { inherit config dotfiles; };
|
file = utils.mk_symlinks { inherit config dotfiles; };
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ rec {
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|
||||||
mkWatchmanTrigger =
|
mkFswatchService =
|
||||||
{
|
{
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
|
|
@ -56,51 +56,55 @@ rec {
|
||||||
isDarwin,
|
isDarwin,
|
||||||
|
|
||||||
name,
|
name,
|
||||||
triggerName,
|
|
||||||
scriptPath,
|
scriptPath,
|
||||||
|
root,
|
||||||
root ? "$HOME/.local/state/colorsync",
|
description ? "Register ${name}.",
|
||||||
description ? "Register watchman trigger for ${name}.",
|
|
||||||
watchExpr ? "current",
|
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
serviceName = "${name}-watchman";
|
scriptPkg = pkgs.writeShellScriptBin "${name}" ''
|
||||||
# e.g. tmux-watchman-statuscolor, ghostty-watchman-theme
|
|
||||||
binName =
|
|
||||||
let
|
|
||||||
trig = lib.replaceStrings [ "_" ] [ "-" ] triggerName;
|
|
||||||
in
|
|
||||||
"${serviceName}-${trig}";
|
|
||||||
|
|
||||||
scriptPkg = pkgs.writeShellScriptBin binName ''
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
ROOT="${root}"
|
ROOT="${root}"
|
||||||
TRIGGER_NAME="${triggerName}"
|
|
||||||
SCRIPT="${scriptPath}"
|
SCRIPT="${scriptPath}"
|
||||||
WATCHMAN="${pkgs.watchman}/bin/watchman"
|
FSWATCH="${pkgs.fswatch}/bin/fswatch"
|
||||||
|
|
||||||
"$WATCHMAN" -- watch-project "$ROOT" >/dev/null
|
echo root:"$ROOT"
|
||||||
"$WATCHMAN" -- trigger-del "$ROOT" "$TRIGGER_NAME" >/dev/null 2>&1 || true
|
echo script:"$SCRIPT"
|
||||||
"$WATCHMAN" -- trigger "$ROOT" "$TRIGGER_NAME" ${watchExpr} -- bash "$SCRIPT"
|
echo fswatch:"$FSWATCH"
|
||||||
|
echo home:"$HOME"
|
||||||
|
|
||||||
|
"$FSWATCH" --latency=0.2 -o "$ROOT" | xargs -n1 "$SCRIPT"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
pathForService = lib.makeBinPath [
|
baseBinPath = lib.makeBinPath [
|
||||||
pkgs.watchman
|
pkgs.findutils
|
||||||
|
pkgs.fswatch
|
||||||
pkgs.bash
|
pkgs.bash
|
||||||
pkgs.coreutils
|
pkgs.coreutils
|
||||||
];
|
];
|
||||||
|
|
||||||
|
pathForService = lib.concatStringsSep ":" [
|
||||||
|
baseBinPath
|
||||||
|
"${config.home.profileDirectory}/bin"
|
||||||
|
"/etc/profiles/per-user/${config.home.username}/bin"
|
||||||
|
"/opt/homebrew/bin"
|
||||||
|
"/usr/local/bin"
|
||||||
|
"/usr/bin"
|
||||||
|
"/bin"
|
||||||
|
];
|
||||||
|
|
||||||
linuxAttrs = lib.optionalAttrs isLinux {
|
linuxAttrs = lib.optionalAttrs isLinux {
|
||||||
systemd.user.startServices = "sd-switch";
|
systemd.user.startServices = "sd-switch";
|
||||||
systemd.user.services."${serviceName}" = {
|
systemd.user.services."${name}" = {
|
||||||
Unit = {
|
Unit = {
|
||||||
Description = description;
|
Description = description;
|
||||||
After = [ "graphical-session.target" ];
|
After = [ "graphical-session.target" ];
|
||||||
};
|
};
|
||||||
Service = {
|
Service = {
|
||||||
Type = "oneshot";
|
Type = "simple";
|
||||||
ExecStart = "${scriptPkg}/bin/${binName}";
|
Restart = "always";
|
||||||
|
RestartSec = "5s";
|
||||||
|
ExecStart = "${scriptPkg}/bin/${name}";
|
||||||
Environment = [ "PATH=${pathForService}" ];
|
Environment = [ "PATH=${pathForService}" ];
|
||||||
StandardOutput = "journal";
|
StandardOutput = "journal";
|
||||||
StandardError = "journal";
|
StandardError = "journal";
|
||||||
|
|
@ -112,17 +116,17 @@ rec {
|
||||||
};
|
};
|
||||||
|
|
||||||
darwinAttrs = lib.optionalAttrs isDarwin {
|
darwinAttrs = lib.optionalAttrs isDarwin {
|
||||||
launchd.agents."${serviceName}" = {
|
launchd.agents."${name}" = {
|
||||||
enable = true;
|
enable = true;
|
||||||
config = {
|
config = {
|
||||||
ProgramArguments = [ "${scriptPkg}/bin/${binName}" ];
|
ProgramArguments = [ "${scriptPkg}/bin/${name}" ];
|
||||||
RunAtLoad = true;
|
RunAtLoad = true;
|
||||||
KeepAlive = false;
|
KeepAlive = true;
|
||||||
EnvironmentVariables = {
|
EnvironmentVariables = {
|
||||||
PATH = pathForService;
|
PATH = pathForService;
|
||||||
};
|
};
|
||||||
StandardOutPath = "${config.home.homeDirectory}/Library/Logs/${serviceName}.log";
|
StandardOutPath = "${config.home.homeDirectory}/Library/Logs/${name}.log";
|
||||||
StandardErrorPath = "${config.home.homeDirectory}/Library/Logs/${serviceName}.err";
|
StandardErrorPath = "${config.home.homeDirectory}/Library/Logs/${name}.err";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
ROOT="$HOME/.local/state/colorsync"
|
|
||||||
TRIGGER_NAME="tmux_statusbar_color"
|
|
||||||
SCRIPT="$HOME/.config/tmux/tmux-statusbar-color.sh"
|
|
||||||
WATCHMAN="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"
|
|
||||||
# watchman -- trigger "$HOME/.local/state/colorsync" tmux_statusbar_color 'current' -- bash "$HOME/.config/tmux/tmux-statusbar-color.sh"
|
|
||||||
|
|
||||||
# watchman watch-project "$HOME/.local/state/colorsync"
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue