1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-07 01:07:00 +00:00
home-manager/modules/programs/oh-my-posh.nix
NAHO 5af1b9a0f1
treewide: standardize shell integration options
Standardize all 'programs.<PROGRAM>.enable<SHELL>Integration' options
with the following new functions:

- lib.hm.shell.mkBashIntegrationOption
- lib.hm.shell.mkFishIntegrationOption
- lib.hm.shell.mkIonIntegrationOption
- lib.hm.shell.mkNushellIntegrationOption
- lib.hm.shell.mkZshIntegrationOption

These functions should default to their corresponding global option:

- home.shell.enableBashIntegration
- home.shell.enableFishIntegration
- home.shell.enableIonIntegration
- home.shell.enableNushellIntegration
- home.shell.enableZshIntegration

All these global options default to the
'home.shell.enableShellIntegration' value.

This hierarchy standardizes the shell integration and increases end-user
flexibility.

BREAKING CHANGE: The following inconsistent default values change from
'false' to 'true':

- programs.zellij.enableBashIntegration
- programs.zellij.enableFishIntegration
- programs.zellij.enableZshIntegration

Link: https://github.com/nix-community/home-manager/pull/6358

Co-authored-by: Robert Helgesson <robert@rycee.net>
2025-02-08 22:49:40 +01:00

95 lines
3 KiB
Nix

{ 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
{file}`$XDG_CONFIG_HOME/oh-my-posh/config.json`. See
<https://ohmyposh.dev/docs/configuration/overview>
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:
<https://ohmyposh.dev/docs/themes>. Because a theme
is essentially a configuration file, this option is not used when a
`configFile` is set.
'';
};
enableBashIntegration =
lib.hm.shell.mkBashIntegrationOption { inherit config; };
enableFishIntegration =
lib.hm.shell.mkFishIntegrationOption { inherit config; };
enableNushellIntegration =
lib.hm.shell.mkNushellIntegrationOption { inherit config; };
enableZshIntegration =
lib.hm.shell.mkZshIntegrationOption { inherit config; };
};
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
'';
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
'';
};
};
}