add tcsh completion support - #9503
Conversation
|
This was created with AI assistance (Gemini Flash/Pro) and likely needs more work:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9503 +/- ##
==========================================
+ Coverage 86.18% 86.21% +0.03%
==========================================
Files 96 96
Lines 17434 17462 +28
Branches 2665 2672 +7
==========================================
+ Hits 15025 15055 +30
+ Misses 1668 1667 -1
+ Partials 741 740 -1 ☔ View full report in Codecov by Harness. |
|
@simaoafonso-pwt Could you have a look at that monkeypatch please? |
Thanks for tagging me, I know that tcsh support is not fully featured, but it was the best I could do. I see that monkey patching is changing a single function, can you please create a diff between that new function, and the one on |
952d70a to
7cf6095
Compare
|
@simaoafonso-pwt I added a draft PR there: |
Thanks, I'll review that. |
d09f173 to
f059162
Compare
|
Rebased onto current master and reworked.
Diff is down from +192/−8 to +122/−7. Title and description updated to match. |
`borg completion tcsh` now generates a usable completion script: - add a tcsh preamble with the dynamic completion helpers (as aliases, since tcsh has no functions) and wire the tcsh patterns up for sort keys, files-cache mode, compression specs, chunker params, relative times, timestamps, file sizes and help topics. - complete archive names, archive IDs (when the token starts with "aid:") and tags. tcsh can neither define functions nor use backquotes there (the completion rule calling the helper is backquoted already), so both helpers run one POSIX sh script that parses $COMMAND_LINE for --repo/-r and queries `borg repo-list`. tcsh has no completion descriptions, so unlike zsh and fish these are plain candidate lists. The generator fixes this needed are all upstream in shtab now (tqdm/shtab#213, released in 1.9.3, which we already require): positional completion under subcommands at any depth, no out-of-range `$cmd` indexing, custom `.complete` patterns in multi-requirement rules, `--opt=` completion, and rule deduplication. One upstream fix is merged but not yet released (tqdm/shtab#241): completion patterns (`f`, `d`, ...) for a positional of a subcommand end up inside a `p@N@` rule, where tcsh runs the clauses as commands and only uses their output, so they do nothing - e.g. `borg umount <TAB>` would not complete a mountpoint. `_tcsh_anchor_positional_patterns` rewrites those into `n/` rules keyed off the preceding (sub)command word, producing exactly what a shtab with borgbackup#241 generates. It is a no-op with such a shtab and can then be removed. Note that tcsh matches completions for positional arguments by word position, so options before an archive name shift it out of place and it is not completed - the `borg completion` epilog points at BORG_REPO for this.
f059162 to
bfb0f5c
Compare
|
Added archive name, tcsh has no functions, and these helpers cannot use backquotes because the completion rule Caveat, now noted in the command's epilog: tcsh matches positional completions by word position, Tests are up to 21 passed / 1 skipped against both shtab 1.9.3 and shtab main. |
borg completion tcshnow generates a usable completion script.Since the original version of this PR, all the generator fixes it used to carry as a local
monkeypatch of
shtab.complete_tcshhave landed upstream in shtab1.9.3, which we already require — positional completion
under subcommands at any depth, no out-of-range
$cmdindexing, custom.completepatterns inmulti-requirement rules,
--opt=completion and rule deduplication. That monkeypatch (132 lines)is therefore gone: with shtab 1.9.3 it produced exactly the same script as stock shtab.
What is left here:
and the tcsh patterns for sort keys, files-cache mode, compression specs, chunker params,
relative times, timestamps, file sizes and help topics
aid:) and tags. tcsh canneither define functions nor use backquotes in these helpers (the completion rule invoking them
is backquoted already), so both run one POSIX sh script that parses
$COMMAND_LINEfor--repo/-rand queriesborg repo-list_tcsh_anchor_positional_patterns(), a temporary ~30-line backport oftqdm/shtab#241 (merged upstream, not released yet)
Why the backport is needed
A completion pattern (
f,d, ...) for a positional of a subcommand ends up inside thatpositional's
p@N@rule. tcsh runs the clauses in such a rule as commands and completes fromtheir output, so a pattern there does nothing at all: without this,
borg umount <TAB>offers nomountpoint and
borg key export <TAB>no path. The fix is to express them asn/<subcommand>/rules instead, which tcsh does apply as patterns.
The rewrite produces byte-identical output to what a shtab containing #241 generates on its own,
and it is a no-op with such a shtab — so it can simply be deleted once we require the release that
contains it. That is noted as a TODO in its docstring.
Not covered
unlike in zsh and fish
archive name shift it out of place and it is not completed - the command's epilog points tcsh
users at BORG_REPO for this. tqdm/shtab#247 fixes
this for options before the subcommand (
borg -r REPO list <TAB>)--compressionisoffered for every subcommand
Testing
Tests pass against both shtab 1.9.3 and current shtab main (21 passed, 1 skipped), and the
generated script was verified by driving a real interactive tcsh 6.21.00:
borg <TAB>,borg key <TAB>,borg key change-location <TAB>,borg help <TAB>,borg umount <TAB>,borg key export <TAB>,borg create --compression=z<TAB>andborg list --sort-by=<TAB>allcomplete as expected. Against a real repository (two archives, two tags),
borg list <TAB>givesthe archive names,
borg list aid:<TAB>givesaid:+ 8 hex digits per archive, andborg tag --add=<TAB>gives the tags.Checklist
master(or maintenance branch if only applicable there)toxor the relevant test subset)