2021-02-04 00:46:16 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.targets.darwin;
|
|
|
|
homeDir = config.home.homeDirectory;
|
|
|
|
confFile = pkgs.writeText "DefaultKeybinding.dict"
|
|
|
|
(lib.generators.toPlist { } cfg.keybindings);
|
|
|
|
in {
|
|
|
|
options.targets.darwin.keybindings = mkOption {
|
|
|
|
type = with types; attrsOf anything;
|
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
"^u" = "deleteToBeginningOfLine:";
|
|
|
|
"^w" = "deleteWordBackward:";
|
|
|
|
};
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-02-04 00:46:16 +01:00
|
|
|
This will configure the default keybindings for text fields in macOS
|
|
|
|
applications. See
|
2023-07-01 01:30:13 +02:00
|
|
|
[Apple's documentation](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html)
|
2021-02-04 00:46:16 +01:00
|
|
|
for more details.
|
|
|
|
|
2023-07-01 01:30:13 +02:00
|
|
|
::: {.warning}
|
|
|
|
Existing keybinding configuration will be wiped when using this
|
|
|
|
option.
|
|
|
|
:::
|
2021-02-04 00:46:16 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.keybindings != { }) {
|
2021-07-07 23:24:27 +02:00
|
|
|
assertions = [
|
|
|
|
(hm.assertions.assertPlatform "targets.darwin.keybindings" pkgs
|
|
|
|
platforms.darwin)
|
|
|
|
];
|
|
|
|
|
2021-02-04 00:46:16 +01:00
|
|
|
# NOTE: just copy the files because symlinks won't be recognized by macOS
|
|
|
|
home.activation.setCocoaKeybindings =
|
|
|
|
hm.dag.entryAfter [ "writeBoundary" ] ''
|
2024-01-23 22:59:26 +01:00
|
|
|
verboseEcho "Configuring keybindings for the Cocoa Text System"
|
2024-01-13 23:15:00 +01:00
|
|
|
run install -Dm644 $VERBOSE_ARG \
|
2021-02-04 00:46:16 +01:00
|
|
|
"${confFile}" "${homeDir}/Library/KeyBindings/DefaultKeyBinding.dict"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|