mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
Add --(enable|disable)-natsort options
This commit is contained in:
parent
ca1f293310
commit
46b88bcb5c
3 changed files with 11 additions and 4 deletions
4
ncdu.pod
4
ncdu.pod
|
|
@ -252,6 +252,10 @@ 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
|
ascending or descending, respectively. e.g. C<--sort=name-desc> will sort by
|
||||||
name in descending order.
|
name in descending order.
|
||||||
|
|
||||||
|
=item B<--enable-natsort>, B<--disable-natsort>
|
||||||
|
|
||||||
|
Enable (default) or disable natural sort when sorting by file name.
|
||||||
|
|
||||||
=item B<--group-directories-first>, B<--no-group-directories-first>
|
=item B<--group-directories-first>, B<--no-group-directories-first>
|
||||||
|
|
||||||
Sort (or not) directories before files.
|
Sort (or not) directories before files.
|
||||||
|
|
|
||||||
|
|
@ -103,10 +103,10 @@ fn sortLt(_: void, ap: ?*model.Entry, bp: ?*model.Entry) bool {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const an = a.name();
|
const an = (if (main.config.sort_order == .asc) a else b).name();
|
||||||
const bn = b.name();
|
const bn = (if (main.config.sort_order == .asc) b else a).name();
|
||||||
return if (main.config.sort_order == .asc) util.strnatcmp(an, bn) == .lt
|
return if (main.config.sort_natural) util.strnatcmp(an, bn) == .lt
|
||||||
else util.strnatcmp(bn, an) == .lt;
|
else std.mem.lessThan(u8, an, bn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should be called when:
|
// Should be called when:
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ pub const config = struct {
|
||||||
pub var sort_col: SortCol = .blocks;
|
pub var sort_col: SortCol = .blocks;
|
||||||
pub var sort_order: SortOrder = .desc;
|
pub var sort_order: SortOrder = .desc;
|
||||||
pub var sort_dirsfirst: bool = false;
|
pub var sort_dirsfirst: bool = false;
|
||||||
|
pub var sort_natural: bool = true;
|
||||||
|
|
||||||
pub var imported: bool = false;
|
pub var imported: bool = false;
|
||||||
pub var can_delete: ?bool = null;
|
pub var can_delete: ?bool = null;
|
||||||
|
|
@ -183,6 +184,8 @@ fn argConfig(args: *Args, opt: Args.Option) bool {
|
||||||
else if (opt.is("--hide-percent")) config.show_percent = false
|
else if (opt.is("--hide-percent")) config.show_percent = false
|
||||||
else if (opt.is("--group-directories-first")) config.sort_dirsfirst = true
|
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("--no-group-directories-first")) config.sort_dirsfirst = false
|
||||||
|
else if (opt.is("--enable-natsort")) config.sort_natural = true
|
||||||
|
else if (opt.is("--disable-natsort")) config.sort_natural = false
|
||||||
else if (opt.is("--graph-style")) {
|
else if (opt.is("--graph-style")) {
|
||||||
const val = args.arg();
|
const val = args.arg();
|
||||||
if (std.mem.eql(u8, val, "hash")) config.graph_style = .hash
|
if (std.mem.eql(u8, val, "hash")) config.graph_style = .hash
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue