From 015a36e9c737d97356eb1627d4d7c7bd84976b85 Mon Sep 17 00:00:00 2001 From: Callum Iddon <19756675+CallumIddon@users.noreply.github.com> Date: Wed, 15 Nov 2023 22:44:42 +1300 Subject: [PATCH] oh-my-posh: enable nushell integration --- modules/programs/oh-my-posh.nix | 21 ++++++++++++++ tests/modules/programs/oh-my-posh/default.nix | 1 + tests/modules/programs/oh-my-posh/nushell.nix | 29 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/modules/programs/oh-my-posh/nushell.nix diff --git a/modules/programs/oh-my-posh.nix b/modules/programs/oh-my-posh.nix index 1c6941caa..8c46a1c69 100644 --- a/modules/programs/oh-my-posh.nix +++ b/modules/programs/oh-my-posh.nix @@ -70,6 +70,14 @@ in { Whether to enable Fish integration. ''; }; + + enableNushellIntegration = mkOption { + type = types.bool; + default = true; + description = '' + Whether to enable Nushell integration. + ''; + }; }; config = mkIf cfg.enable { @@ -90,5 +98,18 @@ in { programs.fish.shellInit = mkIf cfg.enableFishIntegration '' ${cfg.package}/bin/oh-my-posh init fish ${configArgument} | source ''; + + programs.nushell = mkIf cfg.enableNushellIntegration { + extraEnv = '' + let oh_my_posh_cache = "${config.xdg.cacheHome}/oh-my-posh" + if not ($oh_my_posh_cache | path exists) { + mkdir $oh_my_posh_cache + } + ${cfg.package}/bin/oh-my-posh init nu ${configArgument} --print | save --force ${config.xdg.cacheHome}/oh-my-posh/init.nu + ''; + extraConfig = '' + source ${config.xdg.cacheHome}/oh-my-posh/init.nu + ''; + }; }; } diff --git a/tests/modules/programs/oh-my-posh/default.nix b/tests/modules/programs/oh-my-posh/default.nix index 655262566..4b4c9f46f 100644 --- a/tests/modules/programs/oh-my-posh/default.nix +++ b/tests/modules/programs/oh-my-posh/default.nix @@ -2,4 +2,5 @@ oh-my-posh-bash = ./bash.nix; oh-my-posh-zsh = ./zsh.nix; oh-my-posh-fish = ./fish.nix; + oh-my-posh-nushell = ./nushell.nix; } diff --git a/tests/modules/programs/oh-my-posh/nushell.nix b/tests/modules/programs/oh-my-posh/nushell.nix new file mode 100644 index 000000000..2dd6a63cd --- /dev/null +++ b/tests/modules/programs/oh-my-posh/nushell.nix @@ -0,0 +1,29 @@ +{ ... }: + +{ + programs = { + nushell.enable = true; + + oh-my-posh = { + enable = true; + useTheme = "jandedobbeleer"; + }; + }; + + test.stubs = { + oh-my-posh = { }; + nushell = { }; + }; + + nmt.script = '' + assertFileExists home-files/.config/nushell/env.nu + assertFileRegex \ + home-files/.config/nushell/env.nu \ + '/bin/oh-my-posh init nu --config .*--print \| save --force /.*/home-files/\.cache/oh-my-posh/init\.nu' + + assertFileExists home-files/.config/nushell/config.nu + assertFileRegex \ + home-files/.config/nushell/config.nu \ + 'source /.*/\.cache/oh-my-posh/init\.nu' + ''; +}