1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

sioyek: enable multiple bindings for the same command

This commit is contained in:
Gabriel Arazas 2022-10-01 22:42:51 +08:00 committed by Robert Helgesson
parent 3b5a8d3dc7
commit bd87a34bb4
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
6 changed files with 64 additions and 6 deletions

View file

@ -1,11 +1,16 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.sioyek;
renderAttrs = attrs:
concatStringsSep "\n"
(mapAttrsToList (name: value: "${name} ${value}") attrs);
renderConfig = generators.toKeyValue {
mkKeyValue = key: value: "${key} ${value}";
listsAsDuplicateKeys = true;
};
in {
options = {
programs.sioyek = {
@ -24,8 +29,11 @@ in {
Input configuration written to
<filename>$XDG_CONFIG_HOME/sioyek/keys_user.config</filename>.
See <link xlink:href="https://github.com/ahrm/sioyek/blob/main/pdf_viewer/keys.config"/>.
</para><para>
Each attribute could also accept a list of strings to set multiple
bindings of the same command.
'';
type = types.attrsOf types.str;
type = with types; attrsOf (either str (listOf str));
default = { };
example = literalExpression ''
{
@ -33,6 +41,8 @@ in {
"move_down" = "j";
"move_left" = "h";
"move_right" = "l";
"screen_down" = [ "d" "<C-d>" ];
"screen_up" = [ "u" "<C-u>" ];
}
'';
};
@ -59,10 +69,10 @@ in {
config = mkIf cfg.enable (mkMerge [
{ home.packages = [ cfg.package ]; }
(mkIf (cfg.config != { }) {
xdg.configFile."sioyek/prefs_user.config".text = renderAttrs cfg.config;
xdg.configFile."sioyek/prefs_user.config".text = renderConfig cfg.config;
})
(mkIf (cfg.bindings != { }) {
xdg.configFile."sioyek/keys_user.config".text = renderAttrs cfg.bindings;
xdg.configFile."sioyek/keys_user.config".text = renderConfig cfg.bindings;
})
]);

View file

@ -110,6 +110,7 @@ import nmt {
./modules/programs/sagemath
./modules/programs/sbt
./modules/programs/scmpuff
./modules/programs/sioyek
./modules/programs/sm64ex
./modules/programs/ssh
./modules/programs/starship

View file

@ -0,0 +1 @@
{ sioyek = ./sioyek-basic-configuration.nix; }

View file

@ -0,0 +1,36 @@
{ config, pkgs, ... }:
{
programs.sioyek = {
enable = true;
bindings = {
"move_down" = "j";
"move_left" = "h";
"move_right" = "l";
"move_up" = "k";
"screen_down" = [ "d" "<C-d>" ];
"screen_up" = [ "u" "<C-u>" ];
};
config = {
"dark_mode_background_color" = "0.0 0.0 0.0";
"dark_mode_contrast" = "0.8";
};
};
test.stubs.sioyek = { };
nmt = {
description = "Sioyek basic setup with sample configuration";
script = ''
assertFileExists home-files/.config/sioyek/prefs_user.config
assertFileContent home-files/.config/sioyek/prefs_user.config ${
./test_prefs_user.config
}
assertFileExists home-files/.config/sioyek/keys_user.config
assertFileContent home-files/.config/sioyek/keys_user.config ${
./test_keys_user.config
}
'';
};
}

View file

@ -0,0 +1,8 @@
move_down j
move_left h
move_right l
move_up k
screen_down d
screen_down <C-d>
screen_up u
screen_up <C-u>

View file

@ -0,0 +1,2 @@
dark_mode_background_color 0.0 0.0 0.0
dark_mode_contrast 0.8