Rewrite dynamic-colors script in Python
This commit is contained in:
parent
db3beaf568
commit
64205ebebc
1 changed files with 45 additions and 11 deletions
|
|
@ -1,21 +1,55 @@
|
|||
{ nixosConfig, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
dynamic-colors = pkgs.writeShellScriptBin "dynamic-colors" /* bash */ ''
|
||||
case "''$1" in
|
||||
light|dark)
|
||||
if [ -e "''$HOME/.config/alacritty/alacritty-''$1.yml" ]; then
|
||||
ln -sf "''$HOME/.config/alacritty/alacritty-''$1.yml" "$HOME/.config/alacritty/alacritty.yml"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "unknown command ''$1" >&2
|
||||
exit 1
|
||||
esac
|
||||
dynamic-colors = pkgs.writers.writePython3Bin "dynamic-colors" { } ''
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
|
||||
config = [
|
||||
(
|
||||
'~/.config/alacritty',
|
||||
'alacritty-light.yml',
|
||||
'alacritty-dark.yml',
|
||||
'alacritty.yml',
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def main():
|
||||
command, = sys.argv[1:]
|
||||
for directory, light_file, dark_file, config_file in config:
|
||||
directory = pathlib.Path(directory).expanduser()
|
||||
dst = directory.joinpath(config_file)
|
||||
|
||||
if command in ('light', 'dark'):
|
||||
if dst.exists() and dst.is_symlink:
|
||||
os.remove(dst)
|
||||
|
||||
src = {
|
||||
'light': light_file,
|
||||
'dark': dark_file,
|
||||
}[command]
|
||||
|
||||
os.symlink(src, dst)
|
||||
|
||||
else:
|
||||
if dst.exists():
|
||||
continue
|
||||
|
||||
os.symlink(light_file, dst)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
'';
|
||||
in
|
||||
{
|
||||
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