From aba64147062549880c38260a590df446a8575b81 Mon Sep 17 00:00:00 2001 From: Martin Larsson Date: Fri, 25 Jul 2025 00:55:45 +0200 Subject: [PATCH] fix: automated tmux statusbar color now works as it should (only tested on linux) --- flake.nix | 4 ++ nix/home/common/watchman_tmux.nix | 66 +++++++++++++++++++++++ nix/home/darwin.nix | 4 -- nix/home/default.nix | 5 ++ nix/home/linux.nix | 1 - tmux/tmux-watchman-statuscolor-trigger.sh | 14 ++++- tmux/tmux.conf | 2 - zsh/.zshrc | 3 ++ 8 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 nix/home/common/watchman_tmux.nix diff --git a/flake.nix b/flake.nix index 49088e7..0ac4a57 100644 --- a/flake.nix +++ b/flake.nix @@ -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 diff --git a/nix/home/common/watchman_tmux.nix b/nix/home/common/watchman_tmux.nix new file mode 100644 index 0000000..d56fbba --- /dev/null +++ b/nix/home/common/watchman_tmux.nix @@ -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 diff --git a/nix/home/darwin.nix b/nix/home/darwin.nix index b2b08b1..15024ca 100644 --- a/nix/home/darwin.nix +++ b/nix/home/darwin.nix @@ -18,10 +18,6 @@ let ]; in { - imports = [ - ./common/firefox.nix - ]; - home = { packages = with pkgs; [ gawk diff --git a/nix/home/default.nix b/nix/home/default.nix index 85a8338..29f052c 100644 --- a/nix/home/default.nix +++ b/nix/home/default.nix @@ -66,6 +66,11 @@ let ''; in { + imports = [ + ./common/watchman_tmux.nix + ./common/firefox.nix + ]; + programs = { zsh = { enable = true; diff --git a/nix/home/linux.nix b/nix/home/linux.nix index 03f1dee..5ea8ff5 100644 --- a/nix/home/linux.nix +++ b/nix/home/linux.nix @@ -31,7 +31,6 @@ in { imports = [ ./common/theming.nix - ./common/firefox.nix ]; programs = { diff --git a/tmux/tmux-watchman-statuscolor-trigger.sh b/tmux/tmux-watchman-statuscolor-trigger.sh index 80d3a5f..5b295da 100755 --- a/tmux/tmux-watchman-statuscolor-trigger.sh +++ b/tmux/tmux-watchman-statuscolor-trigger.sh @@ -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" diff --git a/tmux/tmux.conf b/tmux/tmux.conf index 25eb8a2..e612435 100644 --- a/tmux/tmux.conf +++ b/tmux/tmux.conf @@ -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" diff --git a/zsh/.zshrc b/zsh/.zshrc index 6f4efaf..23ad36b 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -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