mirror of
https://github.com/nix-community/home-manager
synced 2024-11-10 21:29:48 +01: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:
parent
d94b28d6ff
commit
df3f8d4e8b
2 changed files with 20 additions and 5 deletions
|
@ -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";
|
||||||
|
|
|
@ -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
|
||||||
''
|
''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue