-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathhotkeys.nix
118 lines (106 loc) · 3.28 KB
/
hotkeys.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Global hotkeys (user-defined keyboard shortcuts):
{
pkgs,
config,
lib,
...
}:
let
cfg = config.programs.plasma;
commandString = command: (builtins.replaceStrings [ "%" ] [ "%%" ] command);
group = rec {
name = "plasma-manager-commands";
desktop = "${name}.desktop";
description = "Plasma Manager";
};
commandType =
{ name, ... }:
{
options = {
name = lib.mkOption {
type = lib.types.str;
default = name;
description = "Command hotkey name.";
};
comment = lib.mkOption {
type = lib.types.str;
default = name;
description = "Optional comment to display in the System Settings app.";
};
key = lib.mkOption {
type = lib.types.str;
description = "The key combination that triggers the action.";
default = "";
};
keys = lib.mkOption {
type = with lib.types; listOf str;
description = "The key combinations that trigger the action.";
default = [ ];
};
command = lib.mkOption {
type = lib.types.str;
description = "The command to execute.";
};
logs = {
enabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Connect the command's `stdin` and `stdout` to the systemd journal with `systemd-cat`.";
};
identifier = lib.mkOption {
type = lib.types.str;
default = lib.trivial.pipe name [
lib.strings.toLower
(builtins.replaceStrings [ " " ] [ "-" ])
(n: "${group.name}-${n}")
];
description = "Identifier passed down to `systemd-cat`.";
};
extraArgs = lib.mkOption {
type = lib.types.str;
default = "";
description = "Additional arguments provided to `systemd-cat`.";
};
};
};
};
in
{
options.programs.plasma.hotkeys = {
commands = lib.mkOption {
type = with lib.types; attrsOf (submodule commandType);
default = { };
description = "Commands triggered by a keyboard shortcut.";
};
};
config = lib.mkIf (cfg.enable && builtins.length (builtins.attrNames cfg.hotkeys.commands) != 0) {
xdg.desktopEntries."${group.name}" = {
name = group.description;
noDisplay = true;
type = "Application";
actions = lib.mapAttrs (_: command: {
name = command.name;
exec =
if command.logs.enabled then
"${pkgs.systemd}/bin/systemd-cat --identifier=${command.logs.identifier} ${command.logs.extraArgs} ${commandString command.command}"
else
(commandString command.command);
}) cfg.hotkeys.commands;
};
programs.plasma.configFile."kglobalshortcutsrc"."${group.desktop}" =
{
_k_friendly_name = group.description;
}
// lib.mapAttrs (
_: command:
let
keys = command.keys ++ lib.optionals (command.key != "") [ command.key ];
in
lib.concatStringsSep "," [
(lib.concatStringsSep "\t" (map (lib.escape [ "," ]) keys))
"" # List of default keys, not needed.
command.comment
]
) cfg.hotkeys.commands;
};
}