diff options
author | Yorhel <git@yorhel.nl> | 2021-10-05 17:16:59 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-10-05 17:17:01 +0200 |
commit | 900d31f6fd733227be88f1480c0c78f84f2ed9bb (patch) | |
tree | f828cb813e75dc024177f63b85d7297f34a4843e | |
parent | d005e7c685389cf530ddc6074cbc4965dc13860d (diff) |
Add CLI options for all UI settings
+ reorder manpage a bit, since the scan options tend to be more relevant
than all those UI options.
Again, these are mainly useful with a config file.
-rw-r--r-- | ncdu.pod | 133 | ||||
-rw-r--r-- | src/browser.zig | 28 | ||||
-rw-r--r-- | src/main.zig | 23 |
3 files changed, 123 insertions, 61 deletions
@@ -75,6 +75,58 @@ using 'm' and 'M', respectively. =back +=head2 Scan Options + +These options affect the scanning progress, and have no effect when importing +directory information from a file. + +=over + +=item -x, --one-file-system + +Do not cross filesystem boundaries, i.e. only count files and directories on +the same filesystem as the directory being scanned. + +=item --cross-file-system + +Do cross filesystem boundaries. This is the default, but can be specified to +overrule a previously given C<-x>. + +=item --exclude I<PATTERN> + +Exclude files that match I<PATTERN>. The files will still be displayed by +default, but are not counted towards the disk usage statistics. This argument +can be added multiple times to add more patterns. + +=item -X I<FILE>, --exclude-from I<FILE> + +Exclude files that match any pattern in I<FILE>. Patterns should be separated +by a newline. + +=item --include-caches, --exclude-caches + +Include (default) or exclude directories containing CACHEDIR.TAG. The +directories will still be displayed, but their contents will not be scanned or +counted towards the disk usage statistics. +L<http://www.brynosaurus.com/cachedir/> + +=item -L, --follow-symlinks, --no-follow-symlinks + +Follow (or not) symlinks and count the size of the file they point to. As of +ncdu 1.14, this option will not follow symlinks to directories and will count +each symlinked file as a unique file (i.e. unlike how hard links are handled). +This is subject to change in later versions. + +=item --include-kernfs, --exclude-kernfs + +(Linux only) Include (default) or exclude Linux pseudo filesystems, e.g. /proc +(procfs), /sys (sysfs). + +The complete list of currently known pseudo filesystems is: binfmt, bpf, cgroup, +cgroup2, debug, devpts, proc, pstore, security, selinux, sys, trace. + +=back + =head2 Interface options =over @@ -140,71 +192,62 @@ List sizes using base 10 prefixes, that is, powers of 1000 (KB, MB, etc), as defined in the International System of Units (SI), instead of the usual base 2 prefixes, that is, powers of 1024 (KiB, MiB, etc). -=item --confirm-quit, --no-confirm-quit - -Require a confirmation before quitting ncdu. Very helpful when you accidentally -press 'q' during or after a very long scan. +=item --disk-usage, --apparent-size -=item --color I<SCHEME> +Select whether to display disk usage (default) or apparent sizes. Can also be +toggled in the browser with the 'a' key. -Select a color scheme. The following schemes are recognized: I<off> to disable -colors, I<dark> for a color scheme intended for dark backgrounds and I<dark-bg> -for a variation of the I<dark> color scheme that also works in terminals with a -light background. +=item --show-hidden, --hide-hidden -The default is I<dark-bg> unless the C<NO_COLOR> environment variable is set. +Show (default) or hide "hidden" and excluded files. Can also be toggled in the +browser with the 'e' key. -=back +=item --show-itemcount, --hide-itemcount -=head2 Scan Options +Show or hide (default) the item counts column. Can also be toggled in the +browser with the 'c' key. -These options affect the scanning progress, and have no effect when importing -directory information from a file. +=item --show-mtime, --hide-mtime -=over +Show or hide (default) the last modification time column. Can also be toggled +in the browser with the 'm' key. This option is ignored when not in extended +mode (see C<-e>). -=item -x, --one-file-system +=item --show-graph, --hide-graph -Do not cross filesystem boundaries, i.e. only count files and directories on -the same filesystem as the directory being scanned. +Show (default) or hide the relative size bar column. Can also be toggled in the +browser with the 'g' key. -=item --cross-file-system +=item --show-percent, --hide-percent -Do cross filesystem boundaries. This is the default, but can be specified to -overrule a previously given C<-x>. +Show (default) or hide the relative size percent column. Can also be toggled in +the browser with the 'g' key. -=item --exclude I<PATTERN> +=item --shared-column I<OPTION> -Exclude files that match I<PATTERN>. The files will still be displayed by -default, but are not counted towards the disk usage statistics. This argument -can be added multiple times to add more patterns. +Set to I<off> to disable the shared size column for directories, I<shared> +(default) to display shared directory sizes as a separate column or I<unique> +to display unique directory sizes as a separate column. These options can also +be cycled through in the browser with the 'u' key. -=item -X I<FILE>, --exclude-from I<FILE> - -Exclude files that match any pattern in I<FILE>. Patterns should be separated -by a newline. - -=item --include-caches, --exclude-caches +=item --confirm-quit, --no-confirm-quit -Include (default) or exclude directories containing CACHEDIR.TAG. The -directories will still be displayed, but their contents will not be scanned or -counted towards the disk usage statistics. -L<http://www.brynosaurus.com/cachedir/> +Require a confirmation before quitting ncdu. Very helpful when you accidentally +press 'q' during or after a very long scan. -=item -L, --follow-symlinks, --no-follow-symlinks +=item --confirm-delete, --no-confirm-delete -Follow (or not) symlinks and count the size of the file they point to. As of -ncdu 1.14, this option will not follow symlinks to directories and will count -each symlinked file as a unique file (i.e. unlike how hard links are handled). -This is subject to change in later versions. +Require a confirmation before deleting a file or directory. Enabled by default, +but can be disabled if you're absolutely sure you won't accidentally press 'd'. -=item --include-kernfs, --exclude-kernfs +=item --color I<SCHEME> -(Linux only) Include (default) or exclude Linux pseudo filesystems, e.g. /proc -(procfs), /sys (sysfs). +Select a color scheme. The following schemes are recognized: I<off> to disable +colors, I<dark> for a color scheme intended for dark backgrounds and I<dark-bg> +for a variation of the I<dark> color scheme that also works in terminals with a +light background. -The complete list of currently known pseudo filesystems is: binfmt, bpf, cgroup, -cgroup2, debug, devpts, proc, pstore, security, selinux, sys, trace. +The default is I<dark-bg> unless the C<NO_COLOR> environment variable is set. =back diff --git a/src/browser.zig b/src/browser.zig index a96e618..830fc5e 100644 --- a/src/browser.zig +++ b/src/browser.zig @@ -202,21 +202,19 @@ const Row = struct { } fn graph(self: *Self) void { - if (main.config.show_graph == .off or self.col + 20 > ui.cols) return; + if ((!main.config.show_graph and !main.config.show_percent) or self.col + 20 > ui.cols) return; const bar_size = std.math.max(ui.cols/7, 10); - defer self.col += switch (main.config.show_graph) { - .off => unreachable, - .graph => bar_size + 3, - .percent => 9, - .both => bar_size + 10, - }; + defer self.col += 3 + + (if (main.config.show_graph) bar_size else 0) + + (if (main.config.show_percent) @as(u32, 6) else 0) + + (if (main.config.show_graph and main.config.show_percent) @as(u32, 1) else 0); const item = self.item orelse return; ui.move(self.row, self.col); self.bg.fg(.default); ui.addch('['); - if (main.config.show_graph == .both or main.config.show_graph == .percent) { + if (main.config.show_percent) { self.bg.fg(.num); ui.addprint("{d:>5.1}", .{ 100* if (main.config.show_blocks) @intToFloat(f32, item.blocks) / @intToFloat(f32, std.math.max(1, dir_parent.entry.blocks)) @@ -225,8 +223,8 @@ const Row = struct { self.bg.fg(.default); ui.addch('%'); } - if (main.config.show_graph == .both) ui.addch(' '); - if (main.config.show_graph == .both or main.config.show_graph == .graph) { + if (main.config.show_graph and main.config.show_percent) ui.addch(' '); + if (main.config.show_graph) { const perblock = std.math.divFloor(u64, if (main.config.show_blocks) dir_max_blocks else dir_max_size, bar_size) catch unreachable; const num = if (main.config.show_blocks) item.blocks else item.size; var i: u32 = 0; @@ -920,11 +918,11 @@ pub fn keyInput(ch: i32) void { // Display settings 'c' => main.config.show_items = !main.config.show_items, 'm' => if (main.config.extended) { main.config.show_mtime = !main.config.show_mtime; }, - 'g' => main.config.show_graph = switch (main.config.show_graph) { - .off => .graph, - .graph => .percent, - .percent => .both, - .both => .off, + 'g' => { + if (!main.config.show_graph and !main.config.show_percent) { main.config.show_graph = true; main.config.show_percent = false; } + else if ( main.config.show_graph and !main.config.show_percent) { main.config.show_graph = false; main.config.show_percent = true; } + else if (!main.config.show_graph and main.config.show_percent) { main.config.show_graph = true; main.config.show_percent = true; } + else if ( main.config.show_graph and main.config.show_percent) { main.config.show_graph = false; main.config.show_percent = false; } }, 'u' => main.config.show_shared = switch (main.config.show_shared) { .off => .shared, diff --git a/src/main.zig b/src/main.zig index 42f6042..710f947 100644 --- a/src/main.zig +++ b/src/main.zig @@ -60,7 +60,8 @@ pub const config = struct { pub var show_shared: enum { off, shared, unique } = .shared; pub var show_items: bool = false; pub var show_mtime: bool = false; - pub var show_graph: enum { off, graph, percent, both } = .graph; + pub var show_graph: bool = true; + pub var show_percent: bool = false; pub var sort_col: SortCol = .blocks; pub var sort_order: SortOrder = .desc; pub var sort_dirsfirst: bool = false; @@ -294,6 +295,24 @@ pub fn main() void { else if(opt.is("--disable-delete")) { has_can_delete = true; config.can_delete = false; } else if(opt.is("--enable-refresh")) { has_can_refresh = true; config.can_refresh = true; } else if(opt.is("--disable-refresh")) { has_can_refresh = true; config.can_refresh = false; } + else if(opt.is("--show-hidden")) config.show_hidden = true + else if(opt.is("--hide-hidden")) config.show_hidden = false + else if(opt.is("--show-itemcount")) config.show_items = true + else if(opt.is("--hide-itemcount")) config.show_items = false + else if(opt.is("--show-mtime")) config.show_mtime = true + else if(opt.is("--hide-mtime")) config.show_mtime = false + else if(opt.is("--show-graph")) config.show_graph = true + else if(opt.is("--hide-graph")) config.show_graph = false + else if(opt.is("--show-percent")) config.show_percent = true + else if(opt.is("--hide-percent")) config.show_percent = false + else if(opt.is("--shared-column")) { + const val = args.arg(); + if (std.mem.eql(u8, val, "off")) config.show_shared = .off + else if (std.mem.eql(u8, val, "shared")) config.show_shared = .shared + else if (std.mem.eql(u8, val, "unique")) config.show_shared = .unique + else ui.die("Unknown --shared-column option: {s}.\n", .{val}); + } else if(opt.is("--apparent-size")) config.show_blocks = false + else if(opt.is("--disk-usage")) config.show_blocks = true else if(opt.is("-0")) { has_scan_ui = true; config.scan_ui = .none; } else if(opt.is("-1")) { has_scan_ui = true; config.scan_ui = .line; } else if(opt.is("-2")) { has_scan_ui = true; config.scan_ui = .full; } @@ -315,6 +334,8 @@ pub fn main() void { else if(opt.is("--include-kernfs")) config.exclude_kernfs = false else if(opt.is("--confirm-quit")) config.confirm_quit = true else if(opt.is("--no-confirm-quit")) config.confirm_quit = false + else if(opt.is("--confirm-delete")) config.confirm_delete = true + else if(opt.is("--no-confirm-delete")) config.confirm_delete = false else if(opt.is("--color")) { const val = args.arg(); if (std.mem.eql(u8, val, "off")) config.ui_color = .off |