Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add trailing commas for shortcuts in the services group #110

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions modules/shortcuts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
let
cfg = config.programs.plasma;

# Checks if the shortcut is in the "service" group, in which case we need to
# write the values a little differently.
isService = group:
let
startString = "services/";
in
(builtins.substring 0 (builtins.stringLength startString) group) == startString;

# Convert one shortcut into a settings attribute set.
shortcutToConfigValue = _action: skey:
shortcutToConfigValue = group: _action: skey:
let
# Keys are expected to be a list:
keys =
Expand All @@ -16,18 +24,23 @@ let

# Don't allow un-escaped commas:
escape = lib.escape [ "," ];
keysStr = (if ((builtins.length keys) == 1) then (escape (builtins.head keys)) else "\t" + (lib.concatStringsSep "\t" (map escape keys)));
in
{
value = lib.concatStringsSep "," [
(if ((builtins.length keys) == 1) then (escape (builtins.head keys)) else "\t" + (lib.concatStringsSep "\t" (map escape keys)))
"" # List of default keys, not needed.
"" # Display string, not needed.
];
value =
if (isService group) then
keysStr
else
(lib.concatStringsSep "," [
keysStr
"" # List of default keys, not needed.
"" # Display string, not needed.
]);
};

shortcutsToSettings = groups:
lib.mapAttrs
(group: attrs: (lib.mapAttrs shortcutToConfigValue attrs))
(group: attrs: (lib.mapAttrs (shortcutToConfigValue group) attrs))
groups;
in
{
Expand Down
Loading