mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 21:19:45 +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
1bd1e86464
commit
134deb46ab
2 changed files with 20 additions and 5 deletions
|
@ -8,10 +8,20 @@ let
|
|||
|
||||
package = pkgs.bat;
|
||||
|
||||
toConfigFile = generators.toKeyValue {
|
||||
mkKeyValue = k: v: "--${k}=${lib.escapeShellArg v}";
|
||||
listsAsDuplicateKeys = true;
|
||||
};
|
||||
toConfigFile = attrs:
|
||||
let
|
||||
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 {
|
||||
meta.maintainers = [ ];
|
||||
|
@ -20,7 +30,7 @@ in {
|
|||
enable = mkEnableOption "bat, a cat clone with wings";
|
||||
|
||||
config = mkOption {
|
||||
type = with types; attrsOf (either str (listOf str));
|
||||
type = with types; attrsOf (oneOf [ str (listOf str) bool ]);
|
||||
default = { };
|
||||
example = {
|
||||
theme = "TwoDark";
|
||||
|
|
|
@ -11,6 +11,10 @@ with lib;
|
|||
theme = "TwoDark";
|
||||
pager = "less -FR";
|
||||
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" ''
|
||||
|
@ -32,6 +36,7 @@ with lib;
|
|||
--map-syntax='*.props:Java Properties'
|
||||
--pager='less -FR'
|
||||
--theme='TwoDark'
|
||||
--show-all
|
||||
''
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue