|
| 1 | +{ config, lib, pkgs, ... }: |
| 2 | + |
| 3 | +let |
| 4 | + cfg = config.programs.superfile; |
| 5 | + tomlFormat = pkgs.formats.toml { }; |
| 6 | + inherit (pkgs.stdenv.hostPlatform) isDarwin; |
| 7 | + inherit (lib) |
| 8 | + literalExpression mapAttrs' mkEnableOption mkIf mkMerge mkOption |
| 9 | + mkPackageOption nameValuePair recursiveUpdate types hm; |
| 10 | +in { |
| 11 | + meta.maintainers = [ hm.maintainers.LucasWagler ]; |
| 12 | + |
| 13 | + options.programs.superfile = { |
| 14 | + enable = mkEnableOption |
| 15 | + "superfile - Pretty fancy and modern terminal file manager"; |
| 16 | + |
| 17 | + package = mkPackageOption pkgs "superfile" { nullable = true; }; |
| 18 | + |
| 19 | + settings = mkOption { |
| 20 | + type = tomlFormat.type; |
| 21 | + default = { }; |
| 22 | + description = '' |
| 23 | + Configuration written to {file}`$XDG_CONFIG_HOME/superfile/config.toml` |
| 24 | + (linux) or {file}`Library/Application Support/superfile/config.toml` (darwin), See |
| 25 | + <https://superfile.netlify.app/configure/superfile-config/> for supported values. |
| 26 | + ''; |
| 27 | + example = literalExpression '' |
| 28 | + theme = "catppuccin-frappe"; |
| 29 | + default_sort_type = 0; |
| 30 | + transparent_background = false; |
| 31 | + ''; |
| 32 | + }; |
| 33 | + |
| 34 | + hotkeys = mkOption { |
| 35 | + type = tomlFormat.type; |
| 36 | + default = { }; |
| 37 | + description = '' |
| 38 | + Hotkey configuration written to {file}`$XDG_CONFIG_HOME/superfile/hotkeys.toml` |
| 39 | + (linux) or {file}`Library/Application Support/superfile/hotkeys.toml` (darwin), See |
| 40 | + <https://superfile.netlify.app/configure/custom-hotkeys/> for supported values. |
| 41 | + ''; |
| 42 | + example = literalExpression '' |
| 43 | + confirm = [ |
| 44 | + "enter" |
| 45 | + "right" |
| 46 | + "l" |
| 47 | + ]; |
| 48 | + ''; |
| 49 | + }; |
| 50 | + |
| 51 | + themes = mkOption { |
| 52 | + type = with types; attrsOf (either tomlFormat.type path); |
| 53 | + default = { }; |
| 54 | + description = '' |
| 55 | + Theme files written to {file}`$XDG_CONFIG_HOME/superfile/theme/` |
| 56 | + (linux) or {file}`Library/Application Support/superfile/theme/` (darwin), See |
| 57 | + <https://superfile.netlify.app/configure/custom-theme/> for supported values. |
| 58 | + ''; |
| 59 | + example = literalExpression '' |
| 60 | + myTheme = { |
| 61 | + code_syntax_highlight = "catppuccin-latte"; |
| 62 | +
|
| 63 | + file_panel_border = "#101010"; |
| 64 | + sidebar_border = "#101011"; |
| 65 | + footer_border = "#101012"; |
| 66 | +
|
| 67 | + gradient_color = [ |
| 68 | + "#101013" |
| 69 | + "#101014" |
| 70 | + ]; |
| 71 | +
|
| 72 | + # ... |
| 73 | + }; |
| 74 | + myOtherFavoriteTheme = { |
| 75 | + code_syntax_highlight = "catppuccin-mocha"; |
| 76 | +
|
| 77 | + file_panel_border = "#505050"; |
| 78 | + sidebar_border = "#505051"; |
| 79 | + footer_border = "#505052"; |
| 80 | +
|
| 81 | + gradient_color = [ |
| 82 | + "#505053" |
| 83 | + "#505054" |
| 84 | + ]; |
| 85 | +
|
| 86 | + # ... |
| 87 | + }; |
| 88 | + ''; |
| 89 | + }; |
| 90 | + }; |
| 91 | + |
| 92 | + config = let |
| 93 | + enableXdgConfig = !isDarwin || config.xdg.enable; |
| 94 | + themeSetting = if (!(cfg.settings ? theme) && cfg.themes != { }) then { |
| 95 | + theme = "${builtins.elemAt (builtins.attrNames cfg.themes) 0}"; |
| 96 | + } else |
| 97 | + { }; |
| 98 | + baseConfigPath = if enableXdgConfig then |
| 99 | + "superfile" |
| 100 | + else |
| 101 | + "Library/Application Support/superfile"; |
| 102 | + configFile = mkIf (cfg.settings != { }) { |
| 103 | + "${baseConfigPath}/config.toml".source = |
| 104 | + tomlFormat.generate "superfile-config.toml" |
| 105 | + (recursiveUpdate themeSetting cfg.settings); |
| 106 | + }; |
| 107 | + hotkeysFile = mkIf (cfg.hotkeys != { }) { |
| 108 | + "${baseConfigPath}/hotkeys.toml".source = |
| 109 | + tomlFormat.generate "superfile-hotkeys.toml" (cfg.hotkeys); |
| 110 | + }; |
| 111 | + themeFiles = mapAttrs' (name: value: |
| 112 | + nameValuePair "${baseConfigPath}/theme/${name}.toml" { |
| 113 | + source = if types.path.check value then |
| 114 | + value |
| 115 | + else |
| 116 | + (tomlFormat.generate "superfile-theme-${name}.toml" value); |
| 117 | + }) cfg.themes; |
| 118 | + configFiles = mkMerge [ configFile hotkeysFile themeFiles ]; |
| 119 | + in mkIf cfg.enable { |
| 120 | + home.packages = mkIf (cfg.package != null) [ cfg.package ]; |
| 121 | + |
| 122 | + xdg.configFile = mkIf enableXdgConfig configFiles; |
| 123 | + home.file = mkIf (!enableXdgConfig) configFiles; |
| 124 | + }; |
| 125 | +} |
0 commit comments