Skip to content

Commit bde024c

Browse files
committed
WIP superfile: initial support
1 parent 144f13f commit bde024c

13 files changed

+364
-44
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

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
config,
3+
lib,
4+
pkgs,
5+
...
6+
}:
7+
8+
# TODO: add examples to options
9+
let
10+
cfg = config.programs.superfile;
11+
tomlFormat = pkgs.formats.toml { };
12+
inherit (pkgs.stdenv.hostPlatform) isDarwin;
13+
inherit (lib)
14+
literalExpression
15+
maintainers
16+
mapAttrs'
17+
mkEnableOption
18+
mkIf
19+
mkMerge
20+
mkOption
21+
mkPackageOption
22+
nameValuePair
23+
recursiveUpdate
24+
types
25+
;
26+
in
27+
{
28+
meta.maintainers = with maintainers; [ hm.maintainers.LucasWagler ];
29+
30+
options.programs.superfile = {
31+
enable = mkEnableOption "superfile - Pretty fancy and modern terminal file manager";
32+
package = mkPackageOption pkgs "superfile" { nullable = true; };
33+
34+
settings = mkOption {
35+
type = tomlFormat.type;
36+
default = { }; # TODO?
37+
description = ''
38+
Configuration written to {file}`$XDG_CONFIG_HOME/superfile/config.toml`
39+
(linux) or {file}`Library/Application Support/superfile/config.toml` (darwin), See
40+
<https://superfile.netlify.app/configure/superfile-config/> for supported values.
41+
'';
42+
example = literalExpression ''
43+
theme = "catppuccin-frappe";
44+
default_sort_type = 0;
45+
transparent_background = false;
46+
'';
47+
};
48+
49+
hotkeys = mkOption {
50+
type = tomlFormat.type; # TODO: allow file paths here with a "source"? what's the current accepted default in hm?
51+
default = { }; # TODO?
52+
description = ''
53+
Hotkey configuration written to {file}`$XDG_CONFIG_HOME/superfile/hotkeys.toml`
54+
(linux) or {file}`Library/Application Support/superfile/hotkeys.toml` (darwin), See
55+
<https://superfile.netlify.app/configure/custom-hotkeys/> for supported values.
56+
'';
57+
example = literalExpression "\n";
58+
};
59+
60+
# plugins = mkOption { }; # TODO
61+
62+
themes = mkOption {
63+
type = with types; attrsOf (either tomlFormat.type path);
64+
default = { };
65+
description = ''
66+
Theme files written to {file}`$XDG_CONFIG_HOME/superfile/theme/`
67+
(linux) or {file}`Library/Application Support/superfile/theme/` (darwin), See
68+
<https://superfile.netlify.app/configure/custom-theme/> for supported values.
69+
'';
70+
example = literalExpression "\n";
71+
};
72+
};
73+
74+
config =
75+
let
76+
enableXdgConfig = !isDarwin || config.xdg.enable;
77+
themeSetting =
78+
if (!(cfg.settings ? theme) && cfg.themes != { }) then
79+
{
80+
theme = "${builtins.elemAt (builtins.attrNames cfg.themes) 0}";
81+
}
82+
else
83+
{ };
84+
baseConfigPath = if enableXdgConfig then "superfile" else "Library/Application Support/superfile";
85+
configFile = mkIf (cfg.settings != { }) {
86+
"${baseConfigPath}/config.toml".source = tomlFormat.generate "superfile-config.toml" (
87+
recursiveUpdate themeSetting cfg.settings
88+
);
89+
};
90+
hotkeysFile = mkIf (cfg.hotkeys != { }) {
91+
"${baseConfigPath}/hotkeys.toml".source = tomlFormat.generate "superfile-hotkeys.toml" (
92+
cfg.hotkeys
93+
);
94+
};
95+
themeFiles = mapAttrs' (
96+
name: value:
97+
nameValuePair "${baseConfigPath}/theme/${name}.toml" {
98+
source =
99+
if types.path.check value then
100+
value
101+
else
102+
(tomlFormat.generate "superfile-theme-${name}.toml" value);
103+
}
104+
) cfg.themes;
105+
configFiles = mkMerge [
106+
configFile
107+
hotkeysFile
108+
themeFiles
109+
];
110+
in
111+
mkIf cfg.enable {
112+
home.packages = mkIf (cfg.package != null) [ cfg.package ];
113+
# ++ mkIf (cfg.settings.metadata == true) [ pkgs.exiftool ]; # TODO: how to best handle plugin(s) & deps. Wrapper? symlink stuff? add to path? none? extraPackages? should the user be responsible?
114+
115+
xdg.configFile = mkIf enableXdgConfig configFiles;
116+
home.files = mkIf (!enableXdgConfig) configFiles;
117+
};
118+
}

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

tests/modules/programs/k9s/example-settings.nix

+67-44
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
{ config, pkgs, lib, ... }:
1+
{
2+
config,
3+
pkgs,
4+
lib,
5+
...
6+
}:
27

38
{
49
xdg.enable = lib.mkIf pkgs.stdenv.isDarwin false;
@@ -54,7 +59,11 @@
5459
};
5560
};
5661
};
57-
aliases = { alias = { pp = "v1/pods"; }; };
62+
aliases = {
63+
alias = {
64+
pp = "v1/pods";
65+
};
66+
};
5867
plugin = {
5968
plugin = {
6069
fred = {
@@ -63,59 +72,73 @@
6372
scopes = [ "po" ];
6473
command = "kubectl";
6574
background = false;
66-
args =
67-
[ "logs" "-f" "$NAME" "-n" "$NAMESPACE" "--context" "$CLUSTER" ];
75+
args = [
76+
"logs"
77+
"-f"
78+
"$NAME"
79+
"-n"
80+
"$NAMESPACE"
81+
"--context"
82+
"$CLUSTER"
83+
];
6884
};
6985
};
7086
};
7187
views = {
7288
k9s = {
7389
views = {
7490
"v1/pods" = {
75-
columns = [ "AGE" "NAMESPACE" "NAME" "IP" "NODE" "STATUS" "READY" ];
91+
columns = [
92+
"AGE"
93+
"NAMESPACE"
94+
"NAME"
95+
"IP"
96+
"NODE"
97+
"STATUS"
98+
"READY"
99+
];
76100
};
77101
};
78102
};
79103
};
80104
};
81105

82-
nmt.script = let
83-
configDir = if !pkgs.stdenv.isDarwin then
84-
".config/k9s"
85-
else
86-
"Library/Application Support/k9s";
87-
in ''
88-
assertFileExists "home-files/${configDir}/config.yaml"
89-
assertFileContent \
90-
"home-files/${configDir}/config.yaml" \
91-
${./example-config-expected.yaml}
92-
assertFileExists "home-files/${configDir}/skins/default.yaml"
93-
assertFileContent \
94-
"home-files/${configDir}/skins/default.yaml" \
95-
${./example-skin-expected.yaml}
96-
assertFileExists "home-files/${configDir}/skins/default2.yaml"
97-
assertFileContent \
98-
"home-files/${configDir}/skins/default2.yaml" \
99-
${./example-skin-expected.yaml}
100-
assertFileExists "home-files/${configDir}/skins/alt-skin.yaml"
101-
assertFileContent \
102-
"home-files/${configDir}/skins/alt-skin.yaml" \
103-
${./example-skin-expected-alt.yaml}
104-
assertFileExists "home-files/${configDir}/hotkeys.yaml"
105-
assertFileContent \
106-
"home-files/${configDir}/hotkeys.yaml" \
107-
${./example-hotkey-expected.yaml}
108-
assertFileExists "home-files/${configDir}/aliases.yaml"
109-
assertFileContent \
110-
"home-files/${configDir}/aliases.yaml" \
111-
${./example-aliases-expected.yaml}
112-
assertFileExists "home-files/${configDir}/plugins.yaml"
113-
assertFileContent \
114-
"home-files/${configDir}/plugins.yaml" \
115-
${./example-plugin-expected.yaml}
116-
assertFileExists "home-files/${configDir}/views.yaml"
117-
assertFileContent \
118-
"home-files/${configDir}/views.yaml" \
119-
${./example-views-expected.yaml}
120-
'';
106+
nmt.script =
107+
let
108+
configDir = if !pkgs.stdenv.isDarwin then ".config/k9s" else "Library/Application Support/k9s";
109+
in
110+
''
111+
assertFileExists "home-files/${configDir}/config.yaml"
112+
assertFileContent \
113+
"home-files/${configDir}/config.yaml" \
114+
${./example-config-expected.yaml}
115+
assertFileExists "home-files/${configDir}/skins/default.yaml"
116+
assertFileContent \
117+
"home-files/${configDir}/skins/default.yaml" \
118+
${./example-skin-expected.yaml}
119+
assertFileExists "home-files/${configDir}/skins/default2.yaml"
120+
assertFileContent \
121+
"home-files/${configDir}/skins/default2.yaml" \
122+
${./example-skin-expected.yaml}
123+
assertFileExists "home-files/${configDir}/skins/alt-skin.yaml"
124+
assertFileContent \
125+
"home-files/${configDir}/skins/alt-skin.yaml" \
126+
${./example-skin-expected-alt.yaml}
127+
assertFileExists "home-files/${configDir}/hotkeys.yaml"
128+
assertFileContent \
129+
"home-files/${configDir}/hotkeys.yaml" \
130+
${./example-hotkey-expected.yaml}
131+
assertFileExists "home-files/${configDir}/aliases.yaml"
132+
assertFileContent \
133+
"home-files/${configDir}/aliases.yaml" \
134+
${./example-aliases-expected.yaml}
135+
assertFileExists "home-files/${configDir}/plugins.yaml"
136+
assertFileContent \
137+
"home-files/${configDir}/plugins.yaml" \
138+
${./example-plugin-expected.yaml}
139+
assertFileExists "home-files/${configDir}/views.yaml"
140+
assertFileContent \
141+
"home-files/${configDir}/views.yaml" \
142+
${./example-views-expected.yaml}
143+
'';
121144
}
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,86 @@
1+
{
2+
config,
3+
pkgs,
4+
lib,
5+
...
6+
}:
7+
8+
{
9+
xdg.enable = lib.mkIf pkgs.stdenv.isDarwin false;
10+
11+
programs.superfile = {
12+
enable = true;
13+
package = config.lib.test.mkStubPackage { };
14+
15+
settings = {
16+
theme = "catppuccin-frappe";
17+
default_sort_type = 0;
18+
transparent_background = false;
19+
};
20+
hotkeys = {
21+
confirm = [
22+
"enter"
23+
"right"
24+
"l"
25+
];
26+
};
27+
themes = {
28+
test0 = {
29+
code_syntax_highlight = "catppuccin-latte";
30+
31+
file_panel_border = "#101010";
32+
sidebar_border = "#101011";
33+
footer_border = "#101012";
34+
35+
gradient_color = [
36+
"#101013"
37+
"#101014"
38+
];
39+
};
40+
41+
test1 = ./example-theme-expected.toml;
42+
43+
test2 = {
44+
code_syntax_highlight = "catppuccin-frappe";
45+
46+
file_panel_border = "#202020";
47+
sidebar_border = "#202021";
48+
footer_border = "#202022";
49+
50+
gradient_color = [
51+
"#202023"
52+
"#202024"
53+
];
54+
};
55+
};
56+
};
57+
58+
nmt.script =
59+
let
60+
configSubPath =
61+
if !pkgs.stdenv.isDarwin then ".config/superfile" else "Library/Application Support/superfile";
62+
configBasePath = "home-files/" + configSubPath;
63+
in
64+
''
65+
assertFileExists "${configBasePath}/config.toml"
66+
assertFileContent \
67+
"${configBasePath}/config.toml" \
68+
${./example-config-expected.toml}
69+
assertFileExists "${configBasePath}/hotkeys.toml"
70+
assertFileContent \
71+
"${configBasePath}/hotkeys.toml" \
72+
${./example-hotkeys-expected.toml}
73+
assertFileExists "${configBasePath}/theme/test0.toml"
74+
assertFileContent \
75+
"${configBasePath}/theme/test0.toml" \
76+
${./example-theme-expected.toml}
77+
assertFileExists "${configBasePath}/theme/test1.toml"
78+
assertFileContent \
79+
"${configBasePath}/theme/test1.toml" \
80+
${./example-theme-expected.toml}
81+
assertFileExists "${configBasePath}/theme/test2.toml"
82+
assertFileContent \
83+
"${configBasePath}/theme/test2.toml" \
84+
${./example-theme2-expected.toml}
85+
'';
86+
}
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"

0 commit comments

Comments
 (0)