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