Use config-file for dynamic-colors
This commit is contained in:
parent
d5ed797712
commit
af91a9979c
1 changed files with 34 additions and 30 deletions
|
|
@ -1,50 +1,53 @@
|
|||
{ nixosConfig, lib, pkgs, ... }:
|
||||
{ nixosConfig, lib, config, pkgs, ... }:
|
||||
|
||||
let
|
||||
applicationConfig = [
|
||||
{
|
||||
dir = "~/.config/alacritty";
|
||||
light = "alacritty-light.yml";
|
||||
dark = "alacritty-dark.yml";
|
||||
target = "alacritty.yml";
|
||||
}
|
||||
{
|
||||
dir = "~/.config/wofi";
|
||||
light = "color-light";
|
||||
dark = "color-dark";
|
||||
target = "color";
|
||||
}
|
||||
];
|
||||
dynamic-colors = pkgs.writers.writePython3Bin "dynamic-colors" { } ''
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
|
||||
config = [
|
||||
(
|
||||
'~/.config/alacritty',
|
||||
'alacritty-light.yml',
|
||||
'alacritty-dark.yml',
|
||||
'alacritty.yml',
|
||||
),
|
||||
(
|
||||
'~/.config/wofi',
|
||||
'color-light',
|
||||
'color-dark',
|
||||
'color',
|
||||
)
|
||||
]
|
||||
import json
|
||||
|
||||
|
||||
def main():
|
||||
CONFIG_FILE = "~/.config/dynamic-colors/config.json"
|
||||
with open(pathlib.Path(CONFIG_FILE).expanduser(), "r") as fh:
|
||||
config = json.load(fh)
|
||||
|
||||
command, = sys.argv[1:]
|
||||
for directory, light_file, dark_file, config_file in config:
|
||||
directory = pathlib.Path(directory).expanduser()
|
||||
dst = directory.joinpath(config_file)
|
||||
for entry in config:
|
||||
directory = pathlib.Path(entry['dir']).expanduser()
|
||||
target = directory.joinpath(entry['target'])
|
||||
|
||||
if command in ('light', 'dark'):
|
||||
if dst.exists() and dst.is_symlink:
|
||||
os.remove(dst)
|
||||
if target.exists() and target.is_symlink:
|
||||
os.remove(target)
|
||||
|
||||
src = {
|
||||
'light': light_file,
|
||||
'dark': dark_file,
|
||||
'light': entry['light'],
|
||||
'dark': entry['dark'],
|
||||
}[command]
|
||||
|
||||
os.symlink(src, dst)
|
||||
os.symlink(src, target)
|
||||
|
||||
else:
|
||||
if dst.exists():
|
||||
if target.exists():
|
||||
continue
|
||||
|
||||
os.symlink(light_file, dst)
|
||||
os.symlink(entry['light'], target)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
@ -52,10 +55,11 @@ let
|
|||
'';
|
||||
in
|
||||
{
|
||||
xdg.configFile."dynamic-colors/config.json" = {
|
||||
text = lib.generators.toJSON { } applicationConfig;
|
||||
onChange = "${dynamic-colors}/bin/dynamic-colors install";
|
||||
};
|
||||
home.packages = [
|
||||
dynamic-colors
|
||||
];
|
||||
home.activation.dynamic-colors = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||
$DRY_RUN_CMD ${dynamic-colors}/bin/dynamic-colors install
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue