diff options
author | Yorhel <git@yorhel.nl> | 2021-10-06 13:59:14 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-10-06 13:59:14 +0200 |
commit | d1adcde15cad6686ba460244f6ce41f49395ca90 (patch) | |
tree | 20e2422fbbd910d6be6d1dc47fe24530c3d48199 | |
parent | 39a137c132db5dbaa1f04a10898a44a2ad073c17 (diff) |
Add --ignore-config command line option
-rw-r--r-- | ncdu.pod | 7 | ||||
-rw-r--r-- | src/main.zig | 30 |
2 files changed, 27 insertions, 10 deletions
@@ -73,6 +73,10 @@ information. This enables viewing and sorting by the latest child mtime, or modified time, using 'm' and 'M', respectively. +=item --ignore-config + +Do not attempt to load any configuration files. + =back =head2 Scan Options @@ -272,7 +276,8 @@ Ncdu can be configured by placing command-line options in C</etc/ncdu.conf> or C<$HOME/.config/ncdu/config>. If both files exist, the system configuration will be loaded before the user configuration, allowing users to override options set in the system configuration. Options given on the command line will -override options set in the configuration files. +override options set in the configuration files. The files will not be read at +all when C<--ignore-config> is given on the command line. The configuration file format is simply one command line option per line. Lines starting with C<#> are ignored. Example configuration file: diff --git a/src/main.zig b/src/main.zig index bb26e84..b8f19a5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -306,6 +306,7 @@ fn help() noreturn { \\ --exclude-kernfs Exclude Linux pseudo filesystems (procfs,sysfs,cgroup,...) \\ --confirm-quit Confirm quitting ncdu \\ --color SCHEME Set color scheme (off/dark/dark-bg) + \\ --ignore-config Don't load config files \\ \\Refer to `man ncdu` for the full list of options. \\ @@ -394,16 +395,26 @@ pub fn main() void { } if (std.os.getenvZ("NO_COLOR") == null) config.ui_color = .darkbg; - tryReadArgsFile("/etc/ncdu.conf"); + const loadConf = blk: { + var args = std.process.ArgIteratorPosix.init(); + while (args.next()) |a| + if (std.mem.eql(u8, a, "--ignore-config")) + break :blk false; + break :blk true; + }; - if (std.os.getenvZ("XDG_CONFIG_HOME")) |p| { - var path = std.fs.path.joinZ(allocator, &.{p, "ncdu", "config"}) catch unreachable; - defer allocator.free(path); - tryReadArgsFile(path); - } else if (std.os.getenvZ("HOME")) |p| { - var path = std.fs.path.joinZ(allocator, &.{p, ".config", "ncdu", "config"}) catch unreachable; - defer allocator.free(path); - tryReadArgsFile(path); + if (loadConf) { + tryReadArgsFile("/etc/ncdu.conf"); + + if (std.os.getenvZ("XDG_CONFIG_HOME")) |p| { + var path = std.fs.path.joinZ(allocator, &.{p, "ncdu", "config"}) catch unreachable; + defer allocator.free(path); + tryReadArgsFile(path); + } else if (std.os.getenvZ("HOME")) |p| { + var path = std.fs.path.joinZ(allocator, &.{p, ".config", "ncdu", "config"}) catch unreachable; + defer allocator.free(path); + tryReadArgsFile(path); + } } var scan_dir: ?[]const u8 = null; @@ -427,6 +438,7 @@ pub fn main() void { else if (opt.is("-o")) export_file = allocator.dupeZ(u8, args.arg()) catch unreachable else if (opt.is("-f") and import_file != null) ui.die("The -f flag can only be given once.\n", .{}) else if (opt.is("-f")) import_file = allocator.dupeZ(u8, args.arg()) catch unreachable + else if (opt.is("--ignore-config")) {} else if (argConfig(&args, opt)) {} else ui.die("Unrecognized option '{s}'.\n", .{opt.val}); } |