1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00:00

bat: support boolean flags in config

Previously, users cannot enable boolean flags like `--show-all` in bat's
config since all options were expected to be either a string, or a list
of strings. With this commit boolean flags are simply appended to the
end of the config if they are set to `true`, and discarded otherwise.

For example, the config

    {
      theme = "TwoDark";
      show-all = true;
      lessopen = false;
    }

would produce a config file that looks like

    --theme='TwoDark'
    --show-all

Fixes #4657
This commit is contained in:
Leah Amelia Chen 2023-11-23 00:16:58 +01:00 committed by GitHub
parent 1bd1e86464
commit 134deb46ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View file

@ -8,10 +8,20 @@ let
package = pkgs.bat; package = pkgs.bat;
toConfigFile = generators.toKeyValue { toConfigFile = attrs:
mkKeyValue = k: v: "--${k}=${lib.escapeShellArg v}"; let
listsAsDuplicateKeys = true; inherit (builtins) isBool attrNames;
}; nonBoolFlags = filterAttrs (_: v: !(isBool v)) attrs;
enabledBoolFlags = filterAttrs (_: v: isBool v && v) attrs;
keyValuePairs = generators.toKeyValue {
mkKeyValue = k: v: "--${k}=${lib.escapeShellArg v}";
listsAsDuplicateKeys = true;
} nonBoolFlags;
switches = concatMapStrings (k: ''
--${k}
'') (attrNames enabledBoolFlags);
in keyValuePairs + switches;
in { in {
meta.maintainers = [ ]; meta.maintainers = [ ];
@ -20,7 +30,7 @@ in {
enable = mkEnableOption "bat, a cat clone with wings"; enable = mkEnableOption "bat, a cat clone with wings";
config = mkOption { config = mkOption {
type = with types; attrsOf (either str (listOf str)); type = with types; attrsOf (oneOf [ str (listOf str) bool ]);
default = { }; default = { };
example = { example = {
theme = "TwoDark"; theme = "TwoDark";

View file

@ -11,6 +11,10 @@ with lib;
theme = "TwoDark"; theme = "TwoDark";
pager = "less -FR"; pager = "less -FR";
map-syntax = [ "*.jenkinsfile:Groovy" "*.props:Java Properties" ]; map-syntax = [ "*.jenkinsfile:Groovy" "*.props:Java Properties" ];
show-all = true;
# False boolean options should not appear in the config
lessopen = false;
}; };
themes.testtheme.src = pkgs.writeText "testtheme.tmTheme" '' themes.testtheme.src = pkgs.writeText "testtheme.tmTheme" ''
@ -32,6 +36,7 @@ with lib;
--map-syntax='*.props:Java Properties' --map-syntax='*.props:Java Properties'
--pager='less -FR' --pager='less -FR'
--theme='TwoDark' --theme='TwoDark'
--show-all
'' ''
} }