this repo has no description

feat: allow sorting by mod time with -t/--time

Suggested-by: @steeltormentor@mastodon.social

rockorager.dev 1cad11d9 c6c153d5

verified
+23
+1
README.md
··· 34 34 --hyperlinks=WHEN When to use OSC 8 hyperlinks (always, auto, never) 35 35 --icons=WHEN When to display icons (always, auto, never) 36 36 -l, --long Display extended file metadata 37 + -t, --time Sort the entries by modification time, most recent first 37 38 38 39 ``` 39 40
+3
docs/lsr.1.scd
··· 45 45 *-l*, *--long* 46 46 Display extended file metadata 47 47 48 + *-t*, *--time* 49 + Sort the entries by modification time, most recent first 50 + 48 51 *--version* 49 52 Print the version and exit 50 53
+19
src/main.zig
··· 23 23 \\ --hyperlinks=WHEN When to use OSC 8 hyperlinks (always, auto, never) 24 24 \\ --icons=WHEN When to display icons (always, auto, never) 25 25 \\ -l, --long Display extended file metadata 26 + \\ -t, --time Sort the entries by modification time, most recent first 26 27 \\ 27 28 ; 28 29 ··· 37 38 hyperlinks: When = .auto, 38 39 icons: When = .auto, 39 40 long: bool = false, 41 + sort_by_mod_time: bool = false, 40 42 41 43 directory: [:0]const u8 = ".", 42 44 ··· 162 164 'C' => cmd.opts.shortview = .columns, 163 165 'a' => cmd.opts.all = true, 164 166 'l' => cmd.opts.long = true, 167 + 't' => cmd.opts.sort_by_mod_time = true, 165 168 else => { 166 169 try stderr.print("Invalid opt: '{c}'", .{b}); 167 170 std.process.exit(1); ··· 220 223 std.process.exit(1); 221 224 }; 222 225 cmd.opts.shortview = if (o) .oneline else .columns; 226 + } else if (eql(opt, "time")) { 227 + cmd.opts.sort_by_mod_time = parseArgBool(val) orelse { 228 + try stderr.print("Invalid boolean: '{s}'", .{val}); 229 + std.process.exit(1); 230 + }; 223 231 } else if (eql(opt, "help")) { 224 232 return stderr.writeAll(usage); 225 233 } else if (eql(opt, "version")) { ··· 271 279 try ring.run(.until_done); 272 280 273 281 if (cmd.entries.len == 0) return; 282 + 283 + if (cmd.opts.sort_by_mod_time) { 284 + std.sort.pdq(Entry, cmd.entries, cmd.opts, Entry.lessThan); 285 + } 274 286 275 287 if (cmd.opts.long) { 276 288 try printLong(cmd, bw.writer()); ··· 661 673 (lhs.kind == .directory or rhs.kind == .directory)) 662 674 { 663 675 return lhs.kind == .directory; 676 + } 677 + 678 + if (opts.sort_by_mod_time) { 679 + if (lhs.statx.mtime.sec == rhs.statx.mtime.sec) { 680 + return lhs.statx.mtime.nsec > rhs.statx.mtime.nsec; 681 + } 682 + return lhs.statx.mtime.sec > rhs.statx.mtime.sec; 664 683 } 665 684 666 685 return std.ascii.lessThanIgnoreCase(lhs.name, rhs.name);