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

zellij: Add extraConfig option

Mostly useful as a bridge to set keybinds until an idiomatic way has been implemented
This commit is contained in:
Voreck Lukas 2023-09-16 13:11:31 +02:00
parent d9b88b4352
commit 4dda6397d8
No known key found for this signature in database
GPG key ID: 08EEF358D75D5F25
3 changed files with 98 additions and 7 deletions

View file

@ -51,6 +51,39 @@ in {
enableFishIntegration = mkEnableOption "Fish integration" // {
default = false;
};
extraConfig = mkOption {
type = lib.types.lines;
default = "";
example = ''
keybinds {
// keybinds are divided into modes
normal {
// bind instructions can include one or more keys (both keys will be bound separately)
// bind keys can include one or more actions (all actions will be performed with no sequential guarantees)
bind "Ctrl g" { SwitchToMode "locked"; }
bind "Ctrl p" { SwitchToMode "pane"; }
bind "Alt n" { NewPane; }
bind "Alt h" "Alt Left" { MoveFocusOrTab "Left"; }
}
pane {
bind "h" "Left" { MoveFocus "Left"; }
bind "l" "Right" { MoveFocus "Right"; }
bind "j" "Down" { MoveFocus "Down"; }
bind "k" "Up" { MoveFocus "Up"; }
bind "p" { SwitchFocus; }
}
locked {
bind "Ctrl g" { SwitchToMode "normal"; }
}
}
'';
description = ''
Extra configuration lines
Versions prior to 0.32.0 use Yaml
Versions after 0.32.0 use KDL
'';
};
};
config = mkIf cfg.enable {
@ -59,14 +92,28 @@ in {
# Zellij switched from yaml to KDL in version 0.32.0:
# https://github.com/zellij-org/zellij/releases/tag/v0.32.0
xdg.configFile."zellij/config.yaml" = mkIf
(cfg.settings != { } && (versionOlder cfg.package.version "0.32.0")) {
source = yamlFormat.generate "zellij.yaml" cfg.settings;
};
((cfg.settings != { } || cfg.extraConfig != "")
&& (versionOlder cfg.package.version "0.32.0")) {
source =
let settings = yamlFormat.generate "zellij.yaml" cfg.settings;
in ''
${settings}
${cfg.extraConfig}
'';
};
xdg.configFile."zellij/config.kdl" = mkIf
(cfg.settings != { } && (versionAtLeast cfg.package.version "0.32.0")) {
text = lib.hm.generators.toKDL { } cfg.settings;
};
((cfg.settings != { } || cfg.extraConfig != "")
&& (versionAtLeast cfg.package.version "0.32.0")) {
text = let settings = lib.hm.generators.toKDL { } cfg.settings;
in ''
${settings}
${cfg.extraConfig}
'';
};
programs.bash.initExtra = mkIf cfg.enableBashIntegration (mkOrder 200 ''
eval "$(zellij setup --generate-auto-start bash)"

View file

@ -1 +1,4 @@
{ zellij-enable-shells = ./enable-shells.nix; }
{
zellij-enable-shells = ./enable-shells.nix;
zellij-extra-config = ./extra-config.nix;
}

View file

@ -0,0 +1,41 @@
{ lib, ... }:
let
testInput = ''
keybinds {
// keybinds are divided into modes
normal {
// bind instructions can include one or more keys (both keys will be bound separately)
// bind keys can include one or more actions (all actions will be performed with no sequential guarantees)
bind "Ctrl g" { SwitchToMode "locked"; }
bind "Ctrl p" { SwitchToMode "pane"; }
bind "Alt n" { NewPane; }
bind "Alt h" "Alt Left" { MoveFocusOrTab "Left"; }
}
pane {
bind "h" "Left" { MoveFocus "Left"; }
bind "l" "Right" { MoveFocus "Right"; }
bind "j" "Down" { MoveFocus "Down"; }
bind "k" "Up" { MoveFocus "Up"; }
bind "p" { SwitchFocus; }
}
locked {
bind "Ctrl g" { SwitchToMode "normal"; }
}
}
'';
in {
programs = {
zellij = {
enable = true;
extraConfig = testInput;
};
};
nmt.script = ''
assertFileExists home-files/.config/zellij/config.kdl
assertFileContains \
home-files/.config/zellij/config.kdl \
"${testInput}"
'';
}