diff options
Diffstat (limited to 'modules/common/keys.nix')
| -rw-r--r-- | modules/common/keys.nix | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/modules/common/keys.nix b/modules/common/keys.nix new file mode 100644 index 0000000..9e3c1a2 --- /dev/null +++ b/modules/common/keys.nix @@ -0,0 +1,66 @@ +{ + lib, + config, + tsunamiLib, + ... +}: let + inherit (tsunamiLib) scriptPath; + inherit (lib.strings) escapeShellArg; + cfg = config.tsunami.keys; +in { + options = let + tmuxKey = lib.types.strMatching "^((C|M|S)-)*(.|Enter|Escape|Tab|Up|Down|Left|Right)$"; + inherit (lib) mkOption; + in { + tsunami.keys = { + leader = mkOption { + type = with lib.types; + listOf (submodule { + options = { + name = mkOption {type = str;}; + key = mkOption {type = tmuxKey;}; + exec = mkOption {type = str;}; + }; + }); + }; + + global = mkOption { + type = with lib.types; + listOf (submodule { + options = { + key = mkOption {type = tmuxKey;}; + exec = mkOption {type = str;}; + }; + }); + }; + }; + }; + + config = { + tsunami.scripts = { + "menu" = '' + tmux display-menu \ + -x "#{window_width}" -y S \ + -b none \ + -s "bg=#313244,fg=#9399b2" \ + -S "bg=#313244" \ + -H "bg=#45475a fg=#b4befe" \ + "$@" + ''; + + "leader-menu" = let + args = lib.concatStringsSep " " (builtins.map (f: "${escapeShellArg f.name} ${f.key} ${escapeShellArg f.exec}") cfg.leader); + in '' + ${scriptPath "menu"} ${args} + ''; + }; + tsunami.keys.global = [ + { + key = "C-x"; + exec = "run-shell ${scriptPath "leader-menu"}"; + } + ]; + + tsunami.confs."global-keys" = cfg.global |> builtins.map (f: "bind-key -n ${f.key} ${escapeShellArg f.exec}") |> lib.concatStringsSep "\n"; + }; +} |
