tv alacritty: mkdir and cp only when needed

This commit is contained in:
tv 2023-01-03 16:58:37 +01:00
parent ab36074df1
commit b81598ccd9

View File

@ -51,6 +51,20 @@ let
scrolling.multiplier = 8; scrolling.multiplier = 8;
}; };
config-file = pkgs.writeJSON "alacritty-tv.json" config; config-file = pkgs.writeJSON "alacritty-tv.json" config;
profile = pkgs.writeText "alacritty-tv.profile" /* sh */ ''
# Use home so Alacritty can find the configuration without arguments.
# HOME will be reset once in Alacritty.
HOME=$TMPDIR/Alacritty
export HOME
# Install stored configuration if it has changed.
# This allows for both declarative updates and runtime modifications.
${pkgs.coreutils}/bin/mkdir -p "$HOME"
if test "$(${pkgs.coreutils}/bin/cat "$HOME"/ref)" != ${config-file}; then
echo ${config-file} > "$HOME"/ref
${pkgs.coreutils}/bin/cp ${config-file} "$HOME"/.alacritty.yml
fi
'';
in in
pkgs.symlinkJoin { pkgs.symlinkJoin {
@ -62,27 +76,16 @@ pkgs.symlinkJoin {
set -efu set -efu
# Use home so Alacritty can find the configuration without arguments.
# HOME will be reset once in Alacritty.
HOME=$TMPDIR/Alacritty
export HOME
# Install stored configuration if it has changed.
# This allows for both declarative updates and runtime modifications.
${pkgs.coreutils}/bin/mkdir -p "$HOME"
if test "$(${pkgs.coreutils}/bin/cat "$HOME"/ref)" != ${config-file}; then
echo ${config-file} > "$HOME"/ref
${pkgs.coreutils}/bin/cp ${config-file} "$HOME"/.alacritty.yml
fi
case ''${1-} in case ''${1-} in
--singleton) --singleton)
shift shift
if ! ${pkgs.alacritty}/bin/alacritty msg create-window "$@"; then if ! ${pkgs.alacritty}/bin/alacritty msg create-window "$@"; then
. ${profile}
${pkgs.alacritty}/bin/alacritty "$@" & ${pkgs.alacritty}/bin/alacritty "$@" &
fi fi
;; ;;
*) *)
. ${profile}
exec ${pkgs.alacritty}/bin/alacritty "$@" exec ${pkgs.alacritty}/bin/alacritty "$@"
;; ;;
esac esac