mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 09:18:40 -09:00
Add --ignore-config command line option
This commit is contained in:
parent
39a137c132
commit
d1adcde15c
2 changed files with 27 additions and 10 deletions
7
ncdu.pod
7
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:
|
||||
|
|
|
|||
30
src/main.zig
30
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});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue