Skip to content

Commit 50b14cb

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

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

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

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,45 @@
1+
# When not specified in `programs.superfile.settings.theme`,
2+
# test that the first skin name (alphabetically) is used in the config file
3+
# TODO: it'd be good to add a test for: WHEN settings attribute is undefined or empty THEN the file remains uncreated
4+
{ pkgs, lib, ... }: {
5+
xdg.enable = lib.mkIf pkgs.stdenv.isDarwin false;
6+
7+
programs.superfile = {
8+
enable = true;
9+
settings = { transparent_background = false; };
10+
themes = {
11+
test2 = {
12+
code_syntax_highlight = "catppuccin-frappe";
13+
14+
file_panel_border = "#202020";
15+
sidebar_border = "#202021";
16+
footer_border = "#202022";
17+
18+
gradient_color = [ "#202023" "#202024" ];
19+
};
20+
21+
test0 = {
22+
code_syntax_highlight = "catppuccin-latte";
23+
24+
file_panel_border = "#101010";
25+
sidebar_border = "#101011";
26+
footer_border = "#101012";
27+
28+
gradient_color = [ "#101013" "#101014" ];
29+
};
30+
};
31+
};
32+
33+
nmt.script = let
34+
configSubPath = if !pkgs.stdenv.isDarwin then
35+
".config/superfile"
36+
else
37+
"Library/Application Support/superfile";
38+
configBasePath = "home-files/" + configSubPath;
39+
in ''
40+
assertFileExists ${configBasePath}/config.toml
41+
assertFileContent \
42+
${configBasePath}/config.toml \
43+
${./partial-theme-settings-expected.toml}
44+
'';
45+
}

0 commit comments

Comments
 (0)