Skip to content
Snippets Groups Projects
Commit 46b88bcb authored by Yorhel's avatar Yorhel
Browse files

Add --(enable|disable)-natsort options

parent ca1f2933
No related branches found
No related tags found
No related merge requests found
......@@ -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
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>
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 bn = b.name();
return if (main.config.sort_order == .asc) util.strnatcmp(an, bn) == .lt
else util.strnatcmp(bn, an) == .lt;
const an = (if (main.config.sort_order == .asc) a else b).name();
const bn = (if (main.config.sort_order == .asc) b else a).name();
return if (main.config.sort_natural) util.strnatcmp(an, bn) == .lt
else std.mem.lessThan(u8, an, bn);
}
// Should be called when:
......
......@@ -66,6 +66,7 @@ pub const config = struct {
pub var sort_col: SortCol = .blocks;
pub var sort_order: SortOrder = .desc;
pub var sort_dirsfirst: bool = false;
pub var sort_natural: bool = true;
pub var imported: bool = false;
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("--group-directories-first")) config.sort_dirsfirst = true
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")) {
const val = args.arg();
if (std.mem.eql(u8, val, "hash")) config.graph_style = .hash
......
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