[PATCH nfm] Add config option to show hidden files at launch
Export this patch
In main section:
show_hidden: [true|false]. Defaults to false.
---
example/config.ini | 1 +
src/Config.zig | 12 ++++++++++++
src/nfm.zig | 1 +
3 files changed, 14 insertions(+)
diff --git a/example/config.ini b/example/config.ini
index faaec19915ac..55a776795cd2 100644
--- a/example/config.ini
+++ b/example/config.ini
@@ -4,6 +4,7 @@
[main]
opener = xdg-open;
+ show_hidden = false;
Should be "show-hidden".
[keybinds]
j = cursor-move-down;
diff --git a/src/Config.zig b/src/Config.zig
index 2969bfc51b1c..354d57e2acc0 100644
--- a/src/Config.zig
+++ b/src/Config.zig
@@ -70,6 +70,7 @@ pub const KeyOperation = struct {
};
opener: ?[]const u8 = null,
+ show_hidden: bool = false,
keybinds: std.AutoHashMapUnmanaged(spoon.Input, KeyOperation) = .{},
bookmarks: std.AutoHashMapUnmanaged(spoon.Input, []const u8) = .{},
arena: heap.ArenaAllocator = undefined,
@@ -199,9 +200,20 @@ fn parseConfigFile(self: *Self) !?void {
}
}
+ /// Boolean options authorized in the config file.
+ const bool_options = std.ComptimeStringMap(bool, .{
+ .{ "true", true },
+ .{ "false", false },
+ });
+
fn assignMain(self: *Self, variable: []const u8, value: []const u8, path: []const u8, line: usize) !void {
if (mem.eql(u8, variable, "opener")) {
self.opener = try context.gpa.dupe(u8, value);
+ } else if (mem.eql(u8, variable, "show_hidden")) {
+ self.show_hidden = bool_options.get(value) orelse {
+ log.err("{s}:{}: Boolean allowed: 'true' or 'false'", .{ path, line });
+ return error.BadConfig;
+ };
} else {
// TODO maybe try to find the closes approximation and recommend it to the user?
log.err("{s}:{}: No variable '{s}' in section 'main'", .{ path, line, variable });
diff --git a/src/nfm.zig b/src/nfm.zig
index bcf1abcd7cb5..8c255a515239 100644
--- a/src/nfm.zig
+++ b/src/nfm.zig
@@ -274,6 +274,7 @@ pub fn main() !u8 {
};
};
defer context.config.deinit();
+ if (context.config.show_hidden) context.show_hidden = true;
os.sigaction(os.SIG.TERM, &os.Sigaction{
.handler = .{ .handler = handleSigTerm },
--
2.36.1
nfm/patches: FAILED in 52s
[Add config option to show hidden files at launch][0] from [Hugo Machet][1]
[0]: https://lists.sr.ht/~leon_plickat/nfm/patches/33070
[1]: mailto:mail@hmachet.com
✓ #782218 SUCCESS nfm/patches/alpine.yml https://builds.sr.ht/~leon_plickat/job/782218
✗ #782219 FAILED nfm/patches/freebsd.yml https://builds.sr.ht/~leon_plickat/job/782219
I prefer if config errors also print the wrong string, so that users
can see the mistake easier.
So maybe "{s}:{}: Not a boolean: '{s}'".
Friendly greetings,
Leon Henrik Plickat