herbstluftwm: Make herbstclient alias optional

The `herbstclient` alias in the generated `autostart` made it impossible
to use bash functions.

This makes the `herbstclient` alias optional by adding an extra
`herbstclientAlias` option on the herbstluftwm configuration. The new
option defaults to `false` as to not confuse newcomers to the
herbstluftwm module, which is not a breaking change because it was only
an optimization.
This commit is contained in:
Olmo Kramer
2024-06-22 10:37:42 +02:00
committed by Austin Horstman
parent 39cb677ed9
commit 4767a9c719
7 changed files with 140 additions and 5 deletions

View File

@@ -119,6 +119,24 @@ in
{file}`$XDG_CONFIG_HOME/herbstluftwm/autostart`.
'';
};
enableAlias = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Set an alias for the {command}`herbstclient` command in the
{file}`autostart` script that only stores its arguments and executes
them all at once at the end of the {file}`autostart` script.
This reduces the amount of flickering you get while all options are
being applied and improves the performance.
On the other hand, this makes it more difficult to write bash functions
that call {command}`herbstclient`. You can work around this by calling
{command}`command herbstclient` in your functions to still get some of
the benefits of enabling this alias.
'';
};
};
config = lib.mkIf cfg.enable {
@@ -131,11 +149,13 @@ in
xsession.windowManager.command = "${cfg.package}/bin/herbstluftwm --locked";
xdg.configFile."herbstluftwm/autostart".source = pkgs.writeShellScript "herbstluftwm-autostart" ''
shopt -s expand_aliases
${lib.optionalString cfg.enableAlias ''
shopt -s expand_aliases
# shellcheck disable=SC2142
alias herbstclient='set -- "$@" ";"'
set --
# shellcheck disable=SC2142
alias herbstclient='set -- "$@" ";"'
set --
''}
herbstclient emit_hook reload
@@ -169,7 +189,9 @@ in
herbstclient unlock
${cfg.package}/bin/herbstclient chain ";" "$@"
${lib.optionalString cfg.enableAlias ''
${cfg.package}/bin/herbstclient chain ";" "$@"
''}
'';
};
}