fix: automated tmux statusbar color now works as it should (only tested

on linux)
This commit is contained in:
Martin Larsson 2025-07-25 00:55:45 +02:00
parent 3e1993efbd
commit aba6414706
8 changed files with 90 additions and 9 deletions

View file

@ -113,6 +113,8 @@
}:
let
pkgs = get_pkgs { inherit system; };
isLinux = lib.hasSuffix "-linux" system;
isDarwin = lib.hasSuffix "-darwin" system;
in
home-manager.lib.homeManagerConfiguration {
pkgs = pkgs;
@ -126,6 +128,8 @@
nur = nur.legacyPackages.${system};
ghosttyPkg = ghostty.packages.${system}.ghostty;
colorsync = colorsync.packages.${system}.default;
isLinux = isLinux;
isDarwin = isDarwin;
};
};
in

View file

@ -0,0 +1,66 @@
{
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.user.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

View file

@ -18,10 +18,6 @@ let
];
in
{
imports = [
./common/firefox.nix
];
home = {
packages = with pkgs; [
gawk

View file

@ -66,6 +66,11 @@ let
'';
in
{
imports = [
./common/watchman_tmux.nix
./common/firefox.nix
];
programs = {
zsh = {
enable = true;

View file

@ -31,7 +31,6 @@ in
{
imports = [
./common/theming.nix
./common/firefox.nix
];
programs = {

View file

@ -1,4 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail
watchman watch-project "$HOME/.local/state/colorsync"
watchman -- trigger "$HOME/.local/state/colorsync" tmux_statusbar_color 'current' -- bash "$HOME/.config/tmux/tmux-statusbar-color.sh"
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"

View file

@ -124,13 +124,11 @@ set-hook -g pane-focus-in "run-shell '~/.config/tmux/tmux-rename-window.sh | xar
# Set the right status: Battery, date and time, session name
set -g status-right "#($HOME/.config/tmux/tmux-status-right.sh)"
run-shell '~/.config/tmux/tmux-statusbar-color.sh'
run-shell '~/.config/tmux/tmux-watchman-statuscolor.sh'
set -g status-style bold
# SSH agent forwarding
set-option -g update-environment "SSH_AUTH_SOCK SSH_CONNECTION"
setenv -g SSH_AUTH_SOCK $HOME/.ssh/ssh_auth_sock
set -g @plugin "tmux-plugins/tpm"
run "~/dev/git/tpm/tpm"

View file

@ -224,3 +224,6 @@ if [[ -n "$TMUX" ]]; then
tmux rename-window "$name"
}
fi
# just call watchman to jumpstart the daemon
watchman watch-list >/dev/null 2>&1