diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index a500b20d5..e3255a6a7 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -237,6 +237,9 @@ Makefile @thiagokokada
/modules/programs/octant.nix @06kellyjac
+/modules/programs/oh-my-posh.nix @arjan-s
+/tests/modules/programs/oh-my-posh @arjan-s
+
/modules/programs/opam.nix @marsam
/modules/programs/openssh.nix @rycee
diff --git a/modules/misc/news.nix b/modules/misc/news.nix
index b61a3af43..21303e63d 100644
--- a/modules/misc/news.nix
+++ b/modules/misc/news.nix
@@ -800,6 +800,13 @@ in
A new module is available: 'programs.k9s'.
'';
}
+
+ {
+ time = "2022-11-01T23:57:50+00:00";
+ message = ''
+ A new module is available: 'programs.oh-my-posh'.
+ '';
+ }
];
};
}
diff --git a/modules/modules.nix b/modules/modules.nix
index 5b228c5ff..bfeae7e7f 100644
--- a/modules/modules.nix
+++ b/modules/modules.nix
@@ -140,6 +140,7 @@ let
./programs/obs-studio.nix
./programs/octant.nix
./programs/offlineimap.nix
+ ./programs/oh-my-posh.nix
./programs/opam.nix
./programs/pandoc.nix
./programs/password-store.nix
diff --git a/modules/programs/oh-my-posh.nix b/modules/programs/oh-my-posh.nix
new file mode 100644
index 000000000..d1dfda97f
--- /dev/null
+++ b/modules/programs/oh-my-posh.nix
@@ -0,0 +1,94 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+let
+
+ cfg = config.programs.oh-my-posh;
+
+ jsonFormat = pkgs.formats.json { };
+
+ configArgument = if cfg.settings != { } then
+ "--config ${config.xdg.configHome}/oh-my-posh/config.json"
+ else if cfg.useTheme != null then
+ "--config ${cfg.package}/share/oh-my-posh/themes/${cfg.useTheme}.omp.json"
+ else
+ "";
+
+in {
+ meta.maintainers = [ maintainers.arjan-s ];
+
+ options.programs.oh-my-posh = {
+ enable = mkEnableOption "oh-my-posh, a prompt theme engine for any shell";
+
+ package = mkPackageOption pkgs "oh-my-posh" { };
+
+ settings = mkOption {
+ type = jsonFormat.type;
+ default = { };
+ example = literalExpression ''
+ builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile "''${pkgs.oh-my-posh}/share/oh-my-posh/themes/space.omp.json"))'';
+ description = ''
+ Configuration written to
+ $XDG_CONFIG_HOME/oh-my-posh/config.json. See
+
+ for details. The useTheme option is ignored when this
+ option is used.
+ '';
+ };
+
+ useTheme = mkOption {
+ type = types.nullOr types.str;
+ default = null;
+ description = ''
+ Use one of the official themes. This should be a name from this list:
+ . Because a theme
+ is essentially a configuration file, this option is not used when a
+ configFile is set.
+ '';
+ };
+
+ enableBashIntegration = mkOption {
+ type = types.bool;
+ default = true;
+ description = ''
+ Whether to enable Bash integration.
+ '';
+ };
+
+ enableZshIntegration = mkOption {
+ type = types.bool;
+ default = true;
+ description = ''
+ Whether to enable Zsh integration.
+ '';
+ };
+
+ enableFishIntegration = mkOption {
+ type = types.bool;
+ default = true;
+ description = ''
+ Whether to enable Fish integration.
+ '';
+ };
+ };
+
+ config = mkIf cfg.enable {
+ home.packages = [ cfg.package ];
+
+ xdg.configFile."oh-my-posh/config.json" = mkIf (cfg.settings != { }) {
+ source = jsonFormat.generate "oh-my-posh-settings" cfg.settings;
+ };
+
+ programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
+ eval "$(${cfg.package}/bin/oh-my-posh init bash ${configArgument})"
+ '';
+
+ programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
+ eval "$(${cfg.package}/bin/oh-my-posh init zsh ${configArgument})"
+ '';
+
+ programs.fish.shellInit = mkIf cfg.enableFishIntegration ''
+ ${cfg.package}/bin/oh-my-posh init fish ${configArgument} | source
+ '';
+ };
+}
diff --git a/tests/default.nix b/tests/default.nix
index e84dbf053..e78e24369 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -100,6 +100,7 @@ import nmt {
./modules/programs/nix-index
./modules/programs/nnn
./modules/programs/nushell
+ ./modules/programs/oh-my-posh
./modules/programs/pandoc
./modules/programs/pet
./modules/programs/pistol
diff --git a/tests/modules/programs/oh-my-posh/bash.nix b/tests/modules/programs/oh-my-posh/bash.nix
new file mode 100644
index 000000000..2e3d93ac3
--- /dev/null
+++ b/tests/modules/programs/oh-my-posh/bash.nix
@@ -0,0 +1,21 @@
+{ ... }:
+
+{
+ programs = {
+ bash.enable = true;
+
+ oh-my-posh = {
+ enable = true;
+ useTheme = "jandedobbeleer";
+ };
+ };
+
+ test.stubs.oh-my-posh = { };
+
+ nmt.script = ''
+ assertFileExists home-files/.bashrc
+ assertFileContains \
+ home-files/.bashrc \
+ '/bin/oh-my-posh init bash --config'
+ '';
+}
diff --git a/tests/modules/programs/oh-my-posh/default.nix b/tests/modules/programs/oh-my-posh/default.nix
new file mode 100644
index 000000000..655262566
--- /dev/null
+++ b/tests/modules/programs/oh-my-posh/default.nix
@@ -0,0 +1,5 @@
+{
+ oh-my-posh-bash = ./bash.nix;
+ oh-my-posh-zsh = ./zsh.nix;
+ oh-my-posh-fish = ./fish.nix;
+}
diff --git a/tests/modules/programs/oh-my-posh/fish.nix b/tests/modules/programs/oh-my-posh/fish.nix
new file mode 100644
index 000000000..69dd9ac1b
--- /dev/null
+++ b/tests/modules/programs/oh-my-posh/fish.nix
@@ -0,0 +1,28 @@
+{ lib, ... }:
+
+{
+ programs = {
+ fish.enable = true;
+
+ oh-my-posh = {
+ enable = true;
+ useTheme = "jandedobbeleer";
+ };
+ };
+
+ # Needed to avoid error with dummy fish package.
+ xdg.dataFile."fish/home-manager_generated_completions".source =
+ lib.mkForce (builtins.toFile "empty" "");
+
+ test.stubs = {
+ oh-my-posh = { };
+ fish = { };
+ };
+
+ nmt.script = ''
+ assertFileExists home-files/.config/fish/config.fish
+ assertFileContains \
+ home-files/.config/fish/config.fish \
+ '/bin/oh-my-posh init fish --config'
+ '';
+}
diff --git a/tests/modules/programs/oh-my-posh/zsh.nix b/tests/modules/programs/oh-my-posh/zsh.nix
new file mode 100644
index 000000000..6d2a5bedb
--- /dev/null
+++ b/tests/modules/programs/oh-my-posh/zsh.nix
@@ -0,0 +1,24 @@
+{ ... }:
+
+{
+ programs = {
+ zsh.enable = true;
+
+ oh-my-posh = {
+ enable = true;
+ useTheme = "jandedobbeleer";
+ };
+ };
+
+ test.stubs = {
+ oh-my-posh = { };
+ zsh = { };
+ };
+
+ nmt.script = ''
+ assertFileExists home-files/.zshrc
+ assertFileContains \
+ home-files/.zshrc \
+ '/bin/oh-my-posh init zsh --config'
+ '';
+}