From 6924bcefa22a14249e14cfbe5f38d400fb7cfd67 Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Sat, 31 Aug 2024 12:42:08 +0000 Subject: [PATCH] hmMods/extends: add vscode.keybindingsNext option --- nix/hmModules/extends/default.nix | 1 + nix/hmModules/extends/vscode.nix | 71 +++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 nix/hmModules/extends/vscode.nix diff --git a/nix/hmModules/extends/default.nix b/nix/hmModules/extends/default.nix index d12ef1d..ff0ff8f 100644 --- a/nix/hmModules/extends/default.nix +++ b/nix/hmModules/extends/default.nix @@ -2,5 +2,6 @@ imports = [ # files ./kdeconnect.nix + ./vscode.nix ]; } diff --git a/nix/hmModules/extends/vscode.nix b/nix/hmModules/extends/vscode.nix new file mode 100644 index 0000000..da20f73 --- /dev/null +++ b/nix/hmModules/extends/vscode.nix @@ -0,0 +1,71 @@ +{ + config, + lib, + options, + ... +}: +let + cfg = config.programs.vscode; +in +{ + + options.programs.vscode = { + keybindingsNext = lib.mkOption { + description = '' + More expressive and ordered way to set {option}`programs.vscode.keybindings`. + Both options can be used simultaneously. + + - key bindings are grouped by their key combination + - you can shortcut commands without further options (see example) + ''; + type = + let + bindsType = options.programs.vscode.keybindings.type; + bindModule = bindsType.nestedTypes.elemType; + bindOpts = bindModule.getSubOptions; + inhOpts = + prefix: + builtins.removeAttrs (bindOpts prefix) [ + "_module" + "key" + ]; + inhMod = lib.types.submodule { options = inhOpts [ ]; }; + commType = (bindOpts [ ]).command.type; + bindsNextType = lib.types.either inhMod commType; + bindsListNext = lib.types.listOf bindsNextType; + in + lib.types.attrsOf bindsListNext; + default = { }; + example = { + "ctrl+tab" = [ + { + command = "-workbench.action.quickOpenNavigateNextInEditorPicker"; + when = "inEditorsPicker && inQuickOpen"; + } + "-workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup" + "workbench.action.nextEditor" + ]; + "ctrl+shift+tab" = [ + { + command = "-workbench.action.quickOpenNavigatePreviousInEditorPicker"; + when = "inEditorsPicker && inQuickOpen"; + } + "-workbench.action.quickOpenLeastRecentlyUsedEditorInGroup" + "workbench.action.previousEditor" + ]; + }; + }; + }; + + config.programs.vscode = { + keybindings = + let + expandEntry = opts: if builtins.isAttrs opts then opts else { command = opts; }; + transEntry = key: opts: (expandEntry opts) // { inherit key; }; + transKey = key: opts: map (transEntry key) opts; + transAttr = attr: lib.flatten (lib.mapAttrsToList transKey attr); + in + transAttr config.programs.vscode.keybindingsNext; + }; + +}