feat(terminal): sort, uniq and cut as GNU coreutils 9.4 runs them, with their PowerShell counterparts - #417
Conversation
…th their PowerShell counterparts sort, uniq and cut now read files as well as pipes. Before, `sort file` answered "command not found". Expected outputs come from Ubuntu 24.04 under WSL 2 (coreutils 9.4, en_US.UTF-8, whose order matches fr_FR) and PowerShell 7.6.6 (en-US), captured on 2 October 2026 in a sandbox with the same files. - sort: glibc collation (punctuation, symbols and case only break ties, matched line for line on 69 tricky lines), -b -d -f -h -n -r -u -s -c -o, -k with GNU's begfield/limfield, -t, per-key options, the last-resort comparison reversed only by a global -r, GNU's error messages. - uniq: -c -d -D -u -i (ASCII folding), an output file. cut: -f -d -s, --complement, --output-delimiter, and -c/-b counting bytes like GNU 9.4. - Real options that are not simulated print a note, never a wrong result. - PowerShell: Sort-Object on text (case ignored, ties kept, -Descending, -Unique, -CaseSensitive, -Top, -Bottom), Get-Unique, Select-Object -Unique, Group-Object with its table. A table keeps its frame through Select-Object; Name sorts Get-Process by ProcessName. - Reference page: sort, uniq, cut (76 -> 79 commands). The landing roadmap tells the path from the basics to an intermediate level. terminal-fidelity-auditor compared 301 commands with the real shells; its eight findings are fixed or recorded in the plan. code-reviewer found a prototype lookup in getopt (`sort --constructor`), fixed and tested. Phase 5d, lot 1, PR 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Sorry @thierryvm, you've used your own review budget of 250,000 diff characters for the last 7 days.
You can request another review in 1 day and 17 hours by commenting @sourcery-ai review. Upgrade to get a review now.
Guide du réviseurImplémente Diagramme de séquence du traitement de texte Unix à partir de fichiers ou de pipessequenceDiagram
participant User
participant Engine as TerminalEngine
participant Tool as GNUTextTool
participant FS as VirtualFilesystem
participant Output
User->>Engine: sort/uniq/cut args
Engine->>Tool: runSort/runUniq/runCut(args, stdin, read)
Tool->>FS: read file operands
FS-->>Tool: file contents or error
Tool->>Tool: textLines and transform input
alt output file requested
Tool-->>Engine: writeTo(path, lines)
Engine->>FS: writeFileAt(path, lines)
else terminal output
Tool-->>Engine: lines and status
Engine-->>Output: print result or GNU error
end
Diagramme de séquence du tri et du regroupement PowerShellsequenceDiagram
participant User
participant Engine as TerminalEngine
participant Cmdlet as PowerShellCmdlet
participant Table as PowerShellTable
User->>Engine: Get-Content | Sort-Object/Get-Unique/Group-Object
Engine->>Cmdlet: parsePsArgs(args)
Cmdlet->>Cmdlet: compare or group piped lines
alt tabular input
Cmdlet->>Table: preserve frame and sort/select rows
Table-->>Engine: formatted table
else text input
Cmdlet-->>Engine: sorted, unique, or grouped lines
end
Engine-->>User: PowerShell-compatible output
Modifications au niveau des fichiers
Conseils et commandesInteragir avec Sourcery
Personnaliser votre expérienceAccédez à votre tableau de bord pour :
Obtenir de l’aide
Original review guide in EnglishReviewer's GuideImplements file- and pipe-based Sequence diagram for Unix text processing from files or pipessequenceDiagram
participant User
participant Engine as TerminalEngine
participant Tool as GNUTextTool
participant FS as VirtualFilesystem
participant Output
User->>Engine: sort/uniq/cut args
Engine->>Tool: runSort/runUniq/runCut(args, stdin, read)
Tool->>FS: read file operands
FS-->>Tool: file contents or error
Tool->>Tool: textLines and transform input
alt output file requested
Tool-->>Engine: writeTo(path, lines)
Engine->>FS: writeFileAt(path, lines)
else terminal output
Tool-->>Engine: lines and status
Engine-->>Output: print result or GNU error
end
Sequence diagram for PowerShell sorting and groupingsequenceDiagram
participant User
participant Engine as TerminalEngine
participant Cmdlet as PowerShellCmdlet
participant Table as PowerShellTable
User->>Engine: Get-Content | Sort-Object/Get-Unique/Group-Object
Engine->>Cmdlet: parsePsArgs(args)
Cmdlet->>Cmdlet: compare or group piped lines
alt tabular input
Cmdlet->>Table: preserve frame and sort/select rows
Table-->>Engine: formatted table
else text input
Cmdlet-->>Engine: sorted, unique, or grouped lines
end
Engine-->>User: PowerShell-compatible output
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary
Phase 5d, lot 1, first PR:
sort,uniqandcutwork on files and pipes, faithful to GNU coreutils 9.4, with their PowerShell counterparts. Before,sort file.txtanswered "commande introuvable".Reference shells:
LC_ALL=en_US.UTF-8. The en_US, fr_FR and fr_BE locales were generated for this; their sort order is identical.All captures were made in a sandbox holding the same files, more than 150 commands in all. Git Bash's sort is not the reference here, because its Cygwin collation differs.
Linux / macOS (
src/app/data/commands/textTools.ts)sortuses glibc collation. Punctuation, symbols and case only break ties. A collator matched glibc line for line on 69 tricky lines.-b -d -f -h -n -r -u -s -c -o, and-kwith GNU'sbegfield/limfieldrules and per-key options.-r.-t, plus GNU's exact error messages and exit codes.uniq:-c -d -D -u, and-iwith ASCII-only folding (éandÉstay different). It also takes an output file.cut:-f -d -s,--complementand--output-delimiter.-c/-bcount bytes, as in GNU 9.4: "Tâches" cut at 5 gives "Tâch". Missing files are reported one by one.-g -M -V -z,uniq -f…) and--helpprint a note, never a wrong result.Windows
Sort-Objecton text (and its aliassort): case is ignored and ties keep their order, which is true for PowerShell up to 16 lines. It supports-Descending,-Unique,-CaseSensitive,-Topand-Bottom, with parameters bound by the shared PowerShell binder (sort -u).Get-Unique(gu),Select-Object -Unique, andGroup-Object(group,-NoElement) with PowerShell's table.Sort-Object/Select-Object;NamesortsGet-ProcessbyProcessName;Sort-Object { … }script blocks print a "not simulated" note.Reference and public pages
sort,uniqandcutare added to the reference page with Windows variants, executable examples, common errors and official docs (man7.org, Microsoft Learn; all 7 URLs return 200). The reference goes from 76 to 79 commands, inlandingContent.tsand theindex.htmlFAQ.Checks
terminal-fidelity-auditor: compared 301 commands with the real shells.--helpis wrong for every other command.feature-dev:code-reviewer: found thatsort --constructorreachedObject.prototypeingetopt. This is fixed and tested.curriculumEnvAwareness) caught a prototype lookup on typed command names.INPUT_CMDLETSis now aMap.tscclean, lint clean, vitest 3043 passed / 20 skipped, build OK.Known debt, written down in
docs/plan.md:Get-Content a, bandForEach-Objectare not simulated.--helpfor the other commands.🤖 Generated with Claude Code
Résumé par Sourcery
Implémentation d’un tri de texte multiplateforme fidèle, de la déduplication et de l’extraction de champs, avec une documentation de référence et une validation correspondantes.
Nouvelles fonctionnalités :
sort,uniqetcutpour les fichiers et les pipelines sous Linux et macOS.Sort-Object,Get-Unique,Select-Object -UniqueetGroup-Object.Corrections de bugs :
Améliorations :
Documentation :
Tests :
Original summary in English
Summary by Sourcery
Implement faithful cross-platform text sorting, deduplication, and field extraction with matching reference documentation and validation.
New Features:
sort,uniq, andcutsupport for files and pipelines on Linux and macOS.Sort-Object,Get-Unique,Select-Object -Unique, andGroup-Object.Bug Fixes:
Enhancements:
Documentation:
Tests: