Skip to content

Commit 6bd0a20

Browse files
committed
superfile: initial support
Add initial support for `superfile` file manager.
1 parent 144f13f commit 6bd0a20

12 files changed

+277
-0
lines changed

modules/modules.nix

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ let
238238
./programs/sqls.nix
239239
./programs/ssh.nix
240240
./programs/starship.nix
241+
./programs/superfile.nix
241242
./programs/swayimg.nix
242243
./programs/swaylock.nix
243244
./programs/swayr.nix

modules/programs/superfile.nix

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
}

tests/default.nix

+1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ in import nmtSrc {
294294
./modules/programs/spotify-player
295295
./modules/programs/ssh
296296
./modules/programs/starship
297+
./modules/programs/superfile
297298
./modules/programs/taskwarrior
298299
./modules/programs/tealdeer
299300
./modules/programs/texlive
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
superfile-example-settings = ./example-settings.nix;
3+
superfile-empty-settings = ./empty-settings.nix;
4+
superfile-partial-theme-settings = ./partial-theme-settings.nix;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{ pkgs, lib, ... }:
2+
3+
{
4+
programs.superfile.enable = true;
5+
6+
xdg.enable = lib.mkIf pkgs.stdenv.isDarwin false;
7+
8+
nmt.script = let
9+
configDir = if !pkgs.stdenv.isDarwin then
10+
".config/superfile"
11+
else
12+
"Library/Application Support/superfile";
13+
in ''
14+
assertPathNotExists home-files/${configDir}
15+
'';
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
default_sort_type = 0
2+
theme = "catppuccin-frappe"
3+
transparent_background = false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
confirm = ["enter", "right", "l"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{ config, pkgs, lib, ... }:
2+
3+
{
4+
xdg.enable = lib.mkIf pkgs.stdenv.isDarwin false;
5+
6+
programs.superfile = {
7+
enable = true;
8+
package = config.lib.test.mkStubPackage { };
9+
10+
settings = {
11+
theme = "catppuccin-frappe";
12+
default_sort_type = 0;
13+
transparent_background = false;
14+
};
15+
hotkeys = { confirm = [ "enter" "right" "l" ]; };
16+
themes = {
17+
test0 = {
18+
code_syntax_highlight = "catppuccin-latte";
19+
20+
file_panel_border = "#101010";
21+
sidebar_border = "#101011";
22+
footer_border = "#101012";
23+
24+
gradient_color = [ "#101013" "#101014" ];
25+
};
26+
27+
test1 = ./example-theme-expected.toml;
28+
29+
test2 = {
30+
code_syntax_highlight = "catppuccin-frappe";
31+
32+
file_panel_border = "#202020";
33+
sidebar_border = "#202021";
34+
footer_border = "#202022";
35+
36+
gradient_color = [ "#202023" "#202024" ];
37+
};
38+
};
39+
};
40+
41+
nmt.script = let
42+
configSubPath = if !pkgs.stdenv.isDarwin then
43+
".config/superfile"
44+
else
45+
"Library/Application Support/superfile";
46+
configBasePath = "home-files/" + configSubPath;
47+
in ''
48+
assertFileExists "${configBasePath}/config.toml"
49+
assertFileContent \
50+
"${configBasePath}/config.toml" \
51+
${./example-config-expected.toml}
52+
assertFileExists "${configBasePath}/hotkeys.toml"
53+
assertFileContent \
54+
"${configBasePath}/hotkeys.toml" \
55+
${./example-hotkeys-expected.toml}
56+
assertFileExists "${configBasePath}/theme/test0.toml"
57+
assertFileContent \
58+
"${configBasePath}/theme/test0.toml" \
59+
${./example-theme-expected.toml}
60+
assertFileExists "${configBasePath}/theme/test1.toml"
61+
assertFileContent \
62+
"${configBasePath}/theme/test1.toml" \
63+
${./example-theme-expected.toml}
64+
assertFileExists "${configBasePath}/theme/test2.toml"
65+
assertFileContent \
66+
"${configBasePath}/theme/test2.toml" \
67+
${./example-theme2-expected.toml}
68+
'';
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
code_syntax_highlight = "catppuccin-latte"
2+
file_panel_border = "#101010"
3+
footer_border = "#101012"
4+
gradient_color = ["#101013", "#101014"]
5+
sidebar_border = "#101011"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
code_syntax_highlight = "catppuccin-frappe"
2+
file_panel_border = "#202020"
3+
footer_border = "#202022"
4+
gradient_color = ["#202023", "#202024"]
5+
sidebar_border = "#202021"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
theme = "test0"
2+
transparent_background = false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# When not specified in `programs.superfile.settings.theme`,
2+
# test that the first skin name (alphabetically) is used in the config file
3+
{ pkgs, lib, ... }: {
4+
xdg.enable = lib.mkIf pkgs.stdenv.isDarwin false;
5+
6+
programs.superfile = {
7+
enable = true;
8+
settings = { transparent_background = false; };
9+
themes = {
10+
test2 = {
11+
code_syntax_highlight = "catppuccin-frappe";
12+
13+
file_panel_border = "#202020";
14+
sidebar_border = "#202021";
15+
footer_border = "#202022";
16+
17+
gradient_color = [ "#202023" "#202024" ];
18+
};
19+
20+
test0 = {
21+
code_syntax_highlight = "catppuccin-latte";
22+
23+
file_panel_border = "#101010";
24+
sidebar_border = "#101011";
25+
footer_border = "#101012";
26+
27+
gradient_color = [ "#101013" "#101014" ];
28+
};
29+
};
30+
};
31+
32+
nmt.script = let
33+
configSubPath = if !pkgs.stdenv.isDarwin then
34+
".config/superfile"
35+
else
36+
"Library/Application Support/superfile";
37+
configBasePath = "home-files/" + configSubPath;
38+
in ''
39+
assertFileExists "${configBasePath}/config.toml"
40+
assertFileContent \
41+
"${configBasePath}/config.toml" \
42+
${./partial-theme-settings-expected.toml}
43+
'';
44+
}

0 commit comments

Comments
 (0)