From 859afaad63221ce5caa7a6859e53c9e6b89f9678 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 18 Mar 2024 19:23:33 +0100 Subject: alacritty: simplify profiles; they're just configs --- pkgs/simple/alacritty-tv.nix | 65 ++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 44 deletions(-) (limited to 'pkgs') diff --git a/pkgs/simple/alacritty-tv.nix b/pkgs/simple/alacritty-tv.nix index dd18b42..e61b059 100644 --- a/pkgs/simple/alacritty-tv.nix +++ b/pkgs/simple/alacritty-tv.nix @@ -77,37 +77,14 @@ let { key = "Down"; mods = "Shift|Control"; command = font-size "=0"; } ]; }; - writeProfile = name: config: let - config-file = - assert mylib.types.filename.check name; - pkgs.writeJSON "alacritty-tv-${name}.json" config; - in pkgs.writeText "alacritty-tv-${name}.profile" /* sh */ '' - # Use home so Alacritty can find the configuration without arguments. - # HOME will be reset once in Alacritty. - HOME=$XDG_RUNTIME_DIR/Alacritty-${name} - export HOME - # Tell Alacritty via XDG_RUNTIME_DIR where to create sockets. - # XDG_RUNTIME_DIR needs to be reset manually. - export ALACRITTY_XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" - export BASH_EXTRA_INIT=${pkgs.writeDash "alacritty-tv.cleanup.sh" '' - XDG_RUNTIME_DIR=$ALACRITTY_XDG_RUNTIME_DIR - unset ALACRITTY_XDG_RUNTIME_DIR - unset BASH_EXTRA_INIT - ''} - export XDG_RUNTIME_DIR="$HOME" - - # Install stored configuration if it has changed. - # This allows for both declarative updates and runtime modifications. - # rust-xdg requires XDG_RUNTIME_DIR to be secure: - # https://docs.rs/xdg/2.4.1/src/xdg/lib.rs.html#311 - ${pkgs.coreutils}/bin/mkdir -m 0700 -p "$HOME" - ref=$(! test -e "$HOME"/ref || ${pkgs.coreutils}/bin/cat "$HOME"/ref) - if test "$ref" != ${config-file}; then - echo ${config-file} > "$HOME"/ref - ${pkgs.coreutils}/bin/install -m 644 ${config-file} "$HOME"/.alacritty.yml - fi - ''; + alacritty-configs = + pkgs.write "alacritty-configs" + (lib.mapAttrs' + (name: config: lib.nameValuePair "/${name}.json" { + link = pkgs.writeJSON "alacritty-${name}.json" config; + }) + configs); in pkgs.symlinkJoin { @@ -117,34 +94,34 @@ pkgs.symlinkJoin { # usage: # alacritty [--profile=PROFILE] [--singleton] [ARGS...] # where - # PROFILE one of ${builtins.toJSON (builtins.attrNames configs)} + # PROFILE must have a corresponding file ${alacritty-configs}/PROFILE.json set -efu + profile=default case ''${1-} in - ${lib.concatMapStringsSep "\n" (name: /* sh */ '' - --${mylib.shell.escape name}|--profile=${mylib.shell.escape name}) + --profile=*) + profile=''${1#--profile=} shift - profile=${writeProfile name configs.${name}} - ;; - '') (builtins.attrNames configs)} - *) - profile=${writeProfile "default" configs.default} - ;; esac + config=${alacritty-configs}/$profile.json + + if ! test -e "$config"; then + echo "$0: warning: bad profile: $profile; using default instead" >&2 + profile=default + config=${alacritty-configs}/default.json + fi case ''${1-} in --singleton) shift - if ! ${pkgs.alacritty}/bin/alacritty msg create-window "$@"; then - . "$profile" - ${pkgs.alacritty}/bin/alacritty "$@" & + if ! ${pkgs.alacritty}/bin/alacritty --config-file "$config" msg create-window "$@"; then + ${pkgs.alacritty}/bin/alacritty --config-file "$config" "$@" & fi ;; *) - . "$profile" - exec ${pkgs.alacritty}/bin/alacritty "$@" + exec ${pkgs.alacritty}/bin/alacritty --config-file "$config" "$@" ;; esac '') -- cgit v1.2.3