Skip to content
Snippets Groups Projects
Commit 88c8f13c authored by Yorhel's avatar Yorhel
Browse files

Add CLI options for default sort

parent 900d31f6
No related branches found
No related tags found
No related merge requests found
......@@ -230,6 +230,20 @@ Set to I<off> to disable the shared size column for directories, I<shared>
to display unique directory sizes as a separate column. These options can also
be cycled through in the browser with the 'u' key.
=item --sort I<COLUMN>
Change the default column to sort on. Accepted values are I<disk-usage> (the
default), I<name>, I<apparent-size>, I<itemcount> or I<mtime>. The latter only
makes sense in extended mode, see C<-e>.
The column can be suffixed with I<-asc> or I<-desc> to set the order to
ascending or descending, respectively. e.g. C<--sort=name-desc> will sort by
name in descending order.
=item --group-directories-first, --no-group-directories-first
Sort (or not) directories before files.
=item --confirm-quit, --no-confirm-quit
Require a confirmation before quitting ncdu. Very helpful when you accidentally
......
......@@ -305,7 +305,35 @@ pub fn main() void {
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")) {
else if(opt.is("--group-directories-first")) config.sort_dirsfirst = true
else if(opt.is("--no-group-directories-first")) config.sort_dirsfirst = false
else if(opt.is("--sort")) {
var val: []const u8 = args.arg();
var ord: ?config.SortOrder = null;
if (std.mem.endsWith(u8, val, "-asc")) {
val = val[0..val.len-4];
ord = .asc;
} else if (std.mem.endsWith(u8, val, "-desc")) {
val = val[0..val.len-5];
ord = .desc;
}
if (std.mem.eql(u8, val, "name")) {
config.sort_col = .name;
config.sort_order = ord orelse .asc;
} else if (std.mem.eql(u8, val, "disk-usage")) {
config.sort_col = .blocks;
config.sort_order = ord orelse .desc;
} else if (std.mem.eql(u8, val, "apparent-size")) {
config.sort_col = .size;
config.sort_order = ord orelse .desc;
} else if (std.mem.eql(u8, val, "itemcount")) {
config.sort_col = .items;
config.sort_order = ord orelse .desc;
} else if (std.mem.eql(u8, val, "mtime")) {
config.sort_col = .mtime;
config.sort_order = ord orelse .asc;
} else ui.die("Unknown --sort option: {s}.\n", .{val});
} 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment