diff --git a/ncdu.pod b/ncdu.pod index 9dce23ad43b5d5d6023cab413f4fede1c4cf6fa8..c7f75f3e58a742f585b812733750717b868573c1 100644 --- a/ncdu.pod +++ b/ncdu.pod @@ -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 bb26e846a94f6e9bb8ed5cd6bdeb646e01aff86a..b8f19a5941e41256cc85e173adc8152383df8364 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}); }