ls but with io_uring

Use string length for sorting #9

closed opened by knightpp.bsky.social targeting main from knightpp.bsky.social/lsr: fix-sorting
Labels

None yet.

Participants 2
AT URI
at://did:plc:3zsjx5jgd6dbi4orckspsqiq/sh.tangled.repo.pull/3lpgpgbsf4e22
+409 -3
Diff #0
+409 -3
src/main.zig
··· 289 289 290 290 if (cmd.entries.len == 0) return; 291 291 292 - if (cmd.opts.sort_by_mod_time) { 293 - std.sort.pdq(Entry, cmd.entries, cmd.opts, Entry.lessThan); 294 - } 292 + std.sort.pdq(Entry, cmd.entries, cmd.opts, Entry.lessThan); 295 293 296 294 if (cmd.opts.reverse_sort) { 297 295 std.mem.reverse(Entry, cmd.entries); 296 + 297 + 298 + 299 + 300 + 301 + 302 + 303 + 304 + 305 + 306 + 307 + 308 + 309 + 310 + 311 + 312 + 313 + 314 + 315 + 316 + 317 + 318 + 319 + 320 + 321 + 322 + 323 + 324 + 325 + 326 + 327 + 328 + 329 + 330 + 331 + 332 + 333 + 334 + 335 + 336 + 337 + 338 + 339 + 340 + 341 + 342 + 343 + 344 + 345 + 346 + 347 + 348 + 349 + 350 + 351 + 352 + 353 + 354 + 355 + 356 + 357 + 358 + 359 + 360 + 361 + 362 + 363 + 364 + 365 + 366 + 367 + 368 + 369 + 370 + 371 + 372 + 373 + 374 + 375 + 376 + 377 + 378 + 379 + 380 + 381 + 382 + 383 + 384 + 385 + 386 + 387 + 388 + 389 + 390 + 391 + 392 + 393 + 394 + 395 + 396 + 397 + 398 + 399 + 400 + 401 + 402 + 403 + 404 + 405 + 406 + 407 + 408 + 409 + 410 + 411 + 412 + 413 + 414 + 415 + 416 + 417 + 418 + 419 + 420 + 421 + 422 + 423 + 424 + 425 + 426 + 427 + 428 + 429 + 430 + 431 + 432 + 433 + 434 + 435 + 436 + 437 + 438 + 439 + 440 + 441 + 442 + 443 + 444 + 445 + 446 + 447 + 448 + 449 + 450 + 451 + 452 + 453 + 454 + 455 + 456 + 457 + 458 + 459 + 460 + 461 + 462 + 463 + 464 + 465 + 466 + 467 + 468 + 469 + 470 + 471 + 472 + 473 + 474 + 475 + 476 + 477 + 478 + 479 + 480 + 481 + 482 + 483 + 484 + 485 + 486 + 487 + 488 + 489 + 490 + 491 + 492 + 493 + 494 + 495 + 496 + 497 + 498 + 499 + 500 + 501 + 502 + 503 + 504 + 505 + 506 + 507 + 508 + 509 + 510 + 511 + 512 + 513 + 514 + 515 + 516 + 517 + 518 + 519 + 520 + 521 + 522 + 523 + 524 + 525 + 526 + 527 + 528 + 529 + 530 + 531 + 532 + 533 + 534 + 535 + 536 + 537 + 538 + 539 + 540 + 541 + 542 + 543 + 544 + 545 + 546 + 547 + 548 + 549 + 550 + 551 + 552 + 553 + 554 + 555 + 556 + 557 + 558 + 559 + 560 + 561 + 562 + 563 + 564 + 565 + 566 + 567 + 568 + 569 + 570 + 571 + 572 + 573 + 574 + 575 + 576 + 577 + 578 + 579 + 580 + 581 + 582 + 583 + 584 + 585 + 586 + 587 + 588 + 589 + 590 + 591 + 592 + 593 + 594 + 595 + 596 + 597 + 598 + 599 + 600 + 601 + 602 + 603 + 604 + 605 + 606 + 607 + 608 + 609 + 610 + 611 + 612 + 613 + 614 + 615 + 616 + 617 + 618 + 619 + 620 + 621 + 622 + 623 + 624 + 625 + 626 + 627 + 628 + 629 + 630 + 631 + 632 + 633 + 634 + 635 + 636 + 637 + 638 + 639 + 640 + 641 + 642 + 643 + 644 + 645 + 646 + 647 + 648 + 649 + 650 + 651 + 652 + 653 + 654 + 655 + 656 + 657 + 658 + 659 + 660 + 661 + 662 + 663 + 664 + 665 + 666 + 667 + 668 + 669 + 670 + 671 + 672 + 673 + 674 + 675 + 676 + 677 + 678 + 679 + 680 + 681 + 682 + 683 + 684 + 685 + 686 + 687 + 688 + 689 + 690 + 691 + 692 + 693 + return lhs.statx.mtime.sec > rhs.statx.mtime.sec; 694 + } 695 + 696 + return switch (std.math.order(lhs.name.len, rhs.name.len)) { 697 + .lt => true, 698 + .gt => false, 699 + .eq => std.ascii.lessThanIgnoreCase(lhs.name, rhs.name), 700 + }; 701 + } 702 + 703 + fn modeStr(self: Entry) [10]u8 {

History

1 round 3 comments
sign up or login to add to the discussion
2 commits
expand
Sort always
Include string length into sorting
expand 3 comments

This doesn't seem like the right approach... I don't see any other version of ls that sorts by string length. The output I get in the lsr directory with this patch is:

~/r/t/r/lsr main โ†‘2 ๏” zig build run -- -al
drwxr-xr-x tim tim      -  16 May 15:50 ๓ฐ‰‹ .
drwxr-xr-x tim tim      -  15 May 14:32 ๓ฐ‰‹ ..
drwxr-xr-x tim tim      -  16 May  6:08 ๓ฐ‰‹ nix
drwxr-xr-x tim tim      -  18 May  9:44 ๓ฐ‰‹ src
drwxr-xr-x tim tim      -  18 May  9:44 ๓ฐ‰‹ .git
drwxr-xr-x tim tim      -  14 May 11:06 ๓ฐ‰‹ docs
drwxr-xr-x tim tim      -   7 May  6:19 ๓ฐ‰‹ zig-out
drwxr-xr-x tim tim      -   6 May  8:27 ๓ฐ‰‹ .zig-cache
-rw-r--r-- tim tim  1.0 KB  4 May 17:43 ๓ฐˆค LICENSE
-rw-r--r-- tim tim  2.9 KB  7 May  6:42 ๎šฉ build.zig
-rw-r--r-- tim tim  1.3 KB  6 May  6:20 ๓ฑ„… flake.nix
-rw-r--r-- tim tim  3.0 KB 16 May 15:50 ๎˜‰ README.md
-rw-r--r-- tim tim   29 B   6 May  6:20 ๓ฐˆค .gitignore
-rw-r--r-- tim tim  1.5 KB  6 May  6:20 ๓ฑ„… flake.lock
-rw-r--r-- tim tim  950 B  14 May 11:00 ๎šฉ build.zig.zon
-rw-r--r-- tim tim 60.0 KB  5 May 10:35 ๏‡… screenshot.png

Hmm. Eza prints what I expect in this case. Looking at the code https://github.com/eza-community/eza/blob/e04bdba044c4ef43e77a2c778fa604aeb49dce84/src/fs/filter.rs#L259

They use some smart sorting method.

You are right, my patch breaks ordering. I'll close this PR for now.

closed without merging