fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
2.6 KiB94 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4let
5
6  cfg = config.programs.oh-my-posh;
7
8  jsonFormat = pkgs.formats.json { };
9
10  configArgument = if cfg.settings != { } then
11    "--config ${config.xdg.configHome}/oh-my-posh/config.json"
12  else if cfg.useTheme != null then
13    "--config ${cfg.package}/share/oh-my-posh/themes/${cfg.useTheme}.omp.json"
14  else
15    "";
16
17in {
18  meta.maintainers = [ maintainers.arjan-s ];
19
20  options.programs.oh-my-posh = {
21    enable = mkEnableOption "oh-my-posh, a prompt theme engine for any shell";
22
23    package = mkPackageOption pkgs "oh-my-posh" { };
24
25    settings = mkOption {
26      type = jsonFormat.type;
27      default = { };
28      example = literalExpression ''
29        builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile "''${pkgs.oh-my-posh}/share/oh-my-posh/themes/space.omp.json"))'';
30      description = ''
31        Configuration written to
32        {file}`$XDG_CONFIG_HOME/oh-my-posh/config.json`. See
33        <https://ohmyposh.dev/docs/configuration/overview>
34        for details. The `useTheme` option is ignored when this
35        option is used.
36      '';
37    };
38
39    useTheme = mkOption {
40      type = types.nullOr types.str;
41      default = null;
42      description = ''
43        Use one of the official themes. This should be a name from this list:
44        <https://ohmyposh.dev/docs/themes>. Because a theme
45        is essentially a configuration file, this option is not used when a
46        `configFile` is set.
47      '';
48    };
49
50    enableBashIntegration = mkOption {
51      type = types.bool;
52      default = true;
53      description = ''
54        Whether to enable Bash integration.
55      '';
56    };
57
58    enableZshIntegration = mkOption {
59      type = types.bool;
60      default = true;
61      description = ''
62        Whether to enable Zsh integration.
63      '';
64    };
65
66    enableFishIntegration = mkOption {
67      type = types.bool;
68      default = true;
69      description = ''
70        Whether to enable Fish integration.
71      '';
72    };
73  };
74
75  config = mkIf cfg.enable {
76    home.packages = [ cfg.package ];
77
78    xdg.configFile."oh-my-posh/config.json" = mkIf (cfg.settings != { }) {
79      source = jsonFormat.generate "oh-my-posh-settings" cfg.settings;
80    };
81
82    programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
83      eval "$(${cfg.package}/bin/oh-my-posh init bash ${configArgument})"
84    '';
85
86    programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
87      eval "$(${cfg.package}/bin/oh-my-posh init zsh ${configArgument})"
88    '';
89
90    programs.fish.shellInit = mkIf cfg.enableFishIntegration ''
91      ${cfg.package}/bin/oh-my-posh init fish ${configArgument} | source
92    '';
93  };
94}