From 24d590cc32ca9c685668c3e5a67e57327613d32f Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Mon, 5 Jun 2023 22:46:18 +0200 Subject: [PATCH] wezterm: add integrations for Bash and Zsh (#3934) * wezterm: Add `enableBashIntegration` option * wezterm: Add `enableZshIntegration` option --- modules/programs/wezterm.nix | 15 +++++++++++++++ .../wezterm/bash-integration-default.nix | 14 ++++++++++++++ .../wezterm/bash-integration-disabled.nix | 16 ++++++++++++++++ .../wezterm/bash-integration-enabled.nix | 16 ++++++++++++++++ tests/modules/programs/wezterm/default.nix | 8 ++++++++ .../wezterm/zsh-integration-default.nix | 15 +++++++++++++++ .../wezterm/zsh-integration-disabled.nix | 17 +++++++++++++++++ .../wezterm/zsh-integration-enabled.nix | 17 +++++++++++++++++ 8 files changed, 118 insertions(+) create mode 100644 tests/modules/programs/wezterm/bash-integration-default.nix create mode 100644 tests/modules/programs/wezterm/bash-integration-disabled.nix create mode 100644 tests/modules/programs/wezterm/bash-integration-enabled.nix create mode 100644 tests/modules/programs/wezterm/zsh-integration-default.nix create mode 100644 tests/modules/programs/wezterm/zsh-integration-disabled.nix create mode 100644 tests/modules/programs/wezterm/zsh-integration-enabled.nix diff --git a/modules/programs/wezterm.nix b/modules/programs/wezterm.nix index a9ef7cd7d..08f7dbfcc 100644 --- a/modules/programs/wezterm.nix +++ b/modules/programs/wezterm.nix @@ -7,6 +7,10 @@ let cfg = config.programs.wezterm; tomlFormat = pkgs.formats.toml { }; + shellIntegrationStr = '' + source "${cfg.package}/etc/profile.d/wezterm.sh" + ''; + in { meta.maintainers = [ hm.maintainers.blmhemu ]; @@ -79,6 +83,13 @@ in { ''; }; + enableBashIntegration = mkEnableOption "WezTerm's Bash integration." // { + default = true; + }; + + enableZshIntegration = mkEnableOption "WezTerm's Zsh integration." // { + default = true; + }; }; config = mkIf cfg.enable { @@ -99,5 +110,9 @@ in { nameValuePair "wezterm/colors/${name}.toml" { source = tomlFormat.generate "${name}.toml" { colors = value; }; }) cfg.colorSchemes; + + programs.bash.initExtra = + mkIf cfg.enableBashIntegration shellIntegrationStr; + programs.zsh.initExtra = mkIf cfg.enableZshIntegration shellIntegrationStr; }; } diff --git a/tests/modules/programs/wezterm/bash-integration-default.nix b/tests/modules/programs/wezterm/bash-integration-default.nix new file mode 100644 index 000000000..84f34effb --- /dev/null +++ b/tests/modules/programs/wezterm/bash-integration-default.nix @@ -0,0 +1,14 @@ +{ ... }: + +{ + programs.bash.enable = true; + + # Bash integration is enabled by default. + programs.wezterm.enable = true; + + test.stubs.wezterm = { }; + + nmt.script = '' + assertFileContains home-files/.bashrc 'source "@wezterm@/etc/profile.d/wezterm.sh"' + ''; +} diff --git a/tests/modules/programs/wezterm/bash-integration-disabled.nix b/tests/modules/programs/wezterm/bash-integration-disabled.nix new file mode 100644 index 000000000..43c5f5fd9 --- /dev/null +++ b/tests/modules/programs/wezterm/bash-integration-disabled.nix @@ -0,0 +1,16 @@ +{ ... }: + +{ + programs.bash.enable = true; + + programs.wezterm = { + enable = true; + enableBashIntegration = false; + }; + + test.stubs.wezterm = { }; + + nmt.script = '' + assertFileNotRegex home-files/.bashrc 'source "@wezterm@/etc/profile.d/wezterm.sh"' + ''; +} diff --git a/tests/modules/programs/wezterm/bash-integration-enabled.nix b/tests/modules/programs/wezterm/bash-integration-enabled.nix new file mode 100644 index 000000000..007bc0d1a --- /dev/null +++ b/tests/modules/programs/wezterm/bash-integration-enabled.nix @@ -0,0 +1,16 @@ +{ ... }: + +{ + programs.bash.enable = true; + + programs.wezterm = { + enable = true; + enableBashIntegration = true; + }; + + test.stubs.wezterm = { }; + + nmt.script = '' + assertFileContains home-files/.bashrc 'source "@wezterm@/etc/profile.d/wezterm.sh"' + ''; +} diff --git a/tests/modules/programs/wezterm/default.nix b/tests/modules/programs/wezterm/default.nix index 6a521c9c4..0ed73acb4 100644 --- a/tests/modules/programs/wezterm/default.nix +++ b/tests/modules/programs/wezterm/default.nix @@ -1,4 +1,12 @@ { wezterm-example-setting = ./example-setting.nix; wezterm-empty-setting = ./empty-setting.nix; + + wezterm-bash-integration-default = ./bash-integration-default.nix; + wezterm-bash-integration-disabled = ./bash-integration-disabled.nix; + wezterm-bash-integration-enabled = ./bash-integration-enabled.nix; + + wezterm-zsh-integration-default = ./zsh-integration-default.nix; + wezterm-zsh-integration-disabled = ./zsh-integration-disabled.nix; + wezterm-zsh-integration-enabled = ./zsh-integration-enabled.nix; } diff --git a/tests/modules/programs/wezterm/zsh-integration-default.nix b/tests/modules/programs/wezterm/zsh-integration-default.nix new file mode 100644 index 000000000..cc398c9d9 --- /dev/null +++ b/tests/modules/programs/wezterm/zsh-integration-default.nix @@ -0,0 +1,15 @@ +{ ... }: + +{ + programs.zsh.enable = true; + + # Zsh integration is enabled by default. + programs.wezterm.enable = true; + + test.stubs.wezterm = { }; + test.stubs.zsh = { }; + + nmt.script = '' + assertFileContains home-files/.zshrc 'source "@wezterm@/etc/profile.d/wezterm.sh"' + ''; +} diff --git a/tests/modules/programs/wezterm/zsh-integration-disabled.nix b/tests/modules/programs/wezterm/zsh-integration-disabled.nix new file mode 100644 index 000000000..fe7375245 --- /dev/null +++ b/tests/modules/programs/wezterm/zsh-integration-disabled.nix @@ -0,0 +1,17 @@ +{ ... }: + +{ + programs.zsh.enable = true; + + programs.wezterm = { + enable = true; + enableZshIntegration = false; + }; + + test.stubs.wezterm = { }; + test.stubs.zsh = { }; + + nmt.script = '' + assertFileNotRegex home-files/.zshrc 'source "@wezterm@/etc/profile.d/wezterm.sh"' + ''; +} diff --git a/tests/modules/programs/wezterm/zsh-integration-enabled.nix b/tests/modules/programs/wezterm/zsh-integration-enabled.nix new file mode 100644 index 000000000..4e0928709 --- /dev/null +++ b/tests/modules/programs/wezterm/zsh-integration-enabled.nix @@ -0,0 +1,17 @@ +{ ... }: + +{ + programs.zsh.enable = true; + + programs.wezterm = { + enable = true; + enableZshIntegration = true; + }; + + test.stubs.wezterm = { }; + test.stubs.zsh = { }; + + nmt.script = '' + assertFileContains home-files/.zshrc 'source "@wezterm@/etc/profile.d/wezterm.sh"' + ''; +}