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
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,3 +3,4 @@ home/.config/lazygit/state.yml
|
||||||
neomuttrc.local
|
neomuttrc.local
|
||||||
karabiner/automatic_backups/
|
karabiner/automatic_backups/
|
||||||
result
|
result
|
||||||
|
colorsync_ghostty_theme
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,10 @@ clipboard-paste-protection = false
|
||||||
window-decoration = false
|
window-decoration = false
|
||||||
shell-integration = zsh
|
shell-integration = zsh
|
||||||
|
|
||||||
theme = Ayu Mirage
|
# This is the default fallback theme. This is only used
|
||||||
|
# if the colorsync handled theme file doesn't exist.
|
||||||
|
theme = Ayu
|
||||||
|
config-file = ?colorsync_ghostty_theme
|
||||||
background-opacity = 1.0
|
background-opacity = 1.0
|
||||||
background-blur-radius = 7
|
background-blur-radius = 7
|
||||||
|
|
||||||
|
|
|
||||||
37
ghostty/ghostty-change-theme.sh
Executable file
37
ghostty/ghostty-change-theme.sh
Executable file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
THEME=$(colorsync get)
|
||||||
|
|
||||||
|
OUTPUT="$HOME/.config/ghostty/colorsync_ghostty_theme"
|
||||||
|
|
||||||
|
default() {
|
||||||
|
printf "theme = Ayu" > "$OUTPUT"
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$THEME" in
|
||||||
|
ayudark)
|
||||||
|
default
|
||||||
|
;;
|
||||||
|
ayumirage)
|
||||||
|
printf "theme = Ayu Mirage" > "$OUTPUT"
|
||||||
|
;;
|
||||||
|
ayulight)
|
||||||
|
printf "theme = ayu_light" > "$OUTPUT"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
default
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# once SIGUSR2 is merged in Ghostty, just replace the keystroke hack with pkill -USR2 ghostty
|
||||||
|
case "$(uname)" in
|
||||||
|
Darwin)
|
||||||
|
osascript -e 'tell application "System Events" to keystroke "," using {command down, shift down}'
|
||||||
|
;;
|
||||||
|
Linux)
|
||||||
|
wtype -M ctrl -M shift , -m shift -m ctrl
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unsupported OS"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
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
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./common/watchman_tmux.nix
|
./common/watchman_colorsync_services.nix
|
||||||
./common/firefox.nix
|
./common/firefox.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,4 +46,86 @@ rec {
|
||||||
${pkgs.mkalias}/bin/mkalias "$src" "${outputDir}/$app_name"
|
${pkgs.mkalias}/bin/mkalias "$src" "${outputDir}/$app_name"
|
||||||
done
|
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