Skip to content

Comments

Support for tcsh completion#57

Merged
casperdcl merged 5 commits intoiterative:masterfrom
simaoafonso-pwt:tcsh
Nov 16, 2021
Merged

Support for tcsh completion#57
casperdcl merged 5 commits intoiterative:masterfrom
simaoafonso-pwt:tcsh

Conversation

@simaoafonso-pwt
Copy link
Contributor

This is incomplete due to tcsh limitations, but functional.

See #56

Here are some examples generated with this:

#!/usr/bin/env tcsh
# AUTOMATICALLY GENERATED by `shtab`


# Custom Preamble
set autolist
# End Custom Preamble


complete customcomplete \
        'c/--/(output-name input-file help)/' \
        'c/-/(h i o -)/' \
        'n/-i/f/' \
        'n/--input-file/f/' \
        'n/-o/d/' \
        'n/--output-name/d/' \
        'p/1/(completion process)/' \
        'p@2@`set cmd=($COMMAND_LINE); ( [ "$cmd[2]" == "completion" ] && echo "bash\nzsh\ntcsh" || false ) || ( echo "oa\nob" || false )`@' \
        'p/*/()/'
#!/usr/bin/env tcsh
# AUTOMATICALLY GENERATED by `shtab`



complete pathcomplete \
        'c/--/(help dir print-completion)/' \
        'c/-/(s h -)/' \
        'n/-s/(bash zsh tcsh)/' \
        'n/--print-completion/(bash zsh tcsh)/' \
        'n/--dir/d/' \
        'p/1/f/' \
        'p/*/()/'
#!/usr/bin/env tcsh
# AUTOMATICALLY GENERATED by `shtab`



complete shtab \
        'c/--/(error-unimportable shell preamble verbose prog prefix help version)/' \
        'c/-/(s v u h -)/' \
        'n/-s/(bash zsh tcsh)/' \
        'n/--shell/(bash zsh tcsh)/' \
        'p/*/()/'

@simaoafonso-pwt
Copy link
Contributor Author

Pinging @casperdcl from #56.

@casperdcl casperdcl self-requested a review November 8, 2021 15:33
@casperdcl casperdcl added the enhancement New feature or request label Nov 8, 2021
@simaoafonso-pwt
Copy link
Contributor Author

Friendly ping @casperdcl

Copy link
Collaborator

@casperdcl casperdcl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! Just not sure about the test (seems to imply complete_tcsh doesn't really do much?)

@simaoafonso-pwt
Copy link
Contributor Author

I can squash everything into a single commit in the end, if you prefer.

@casperdcl
Copy link
Collaborator

I can squash everything into a single commit in the end, if you prefer.

no need, it's ok :)

@casperdcl casperdcl force-pushed the tcsh branch 3 times, most recently from 0461bf9 to b2e5a2c Compare November 16, 2021 00:52
Copy link
Collaborator

@casperdcl casperdcl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! can you update docs/use.md (used to generate https://docs.iterative.ai/shtab/use/) with installation instructions for tcsh?

simaoafonso-pwt added a commit to simaoafonso-pwt/shtab that referenced this pull request Nov 16, 2021
Copy link
Collaborator

@casperdcl casperdcl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor improvements

simaoafonso-pwt and others added 5 commits November 16, 2021 16:50
This is incomplete due to tcsh limitations, but functional (iterative#56)

Make customcomplete herder to parser

Mixup main parser positionals and sub-parser positionals on the same
"position".
Tweak customcomplete completion

See iterative#57 (comment)
@casperdcl casperdcl merged commit 46302c5 into iterative:master Nov 16, 2021
Copy link
Collaborator

@casperdcl casperdcl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, thanks!

@casperdcl
Copy link
Collaborator

casperdcl commented Nov 16, 2021

/tag v1.5.0 25e3e44

@simaoafonso-pwt
Copy link
Contributor Author

Thanks for the quick review.

@simaoafonso-pwt
Copy link
Contributor Author

https://github.com/iterative/shtab/runs/4227856457?check_suite_focus=true#step:5:31

Oops, I did not run the tests on python 2.7, and nether did the actions run when I pushed.

recurse_parser(subparser, positional_idx, [*requirements, subcmd])

' && '.join([*checks, '']), # Append the separator

Unpacking lists doesn't work. Did a quick test, you can apply this patch:

diff --git i/shtab/__init__.py w/shtab/__init__.py
index d3747f7..da279b4 100644
--- i/shtab/__init__.py
+++ w/shtab/__init__.py
@@ -641,7 +641,7 @@ def complete_tcsh(parser, root_prefix=None, preamble="", choice_functions=None):
                 if not requirements and isinstance(positional.choices, dict):
                     for subcmd, subparser in positional.choices.items():
                         log.debug('%s| | SubParser: %s', log_prefix, subcmd)
-                        recurse_parser(subparser, positional_idx, [*requirements, subcmd])
+                        recurse_parser(subparser, positional_idx, [r for r in requirements] + [subcmd])

     recurse_parser(parser, 0)

@@ -658,7 +658,7 @@ def complete_tcsh(parser, root_prefix=None, preamble="", choice_functions=None):
                     '[ "$cmd[{}]" == "{}" ]'.format(iidx, n) for iidx, n in enumerate(nn, start=2)]
                 if arg.choices:
                     nlist.append('( {}echo "{}" || false )'.format(
-                        ' && '.join([*checks, '']),                 # Append the separator
+                        ' && '.join([c for c in checks] + ['']),                 # Append the separator
                         '\\n'.join(arg.choices),
                     ))

@casperdcl casperdcl linked an issue Nov 16, 2021 that may be closed by this pull request
@casperdcl
Copy link
Collaborator

casperdcl commented Nov 16, 2021

yes I think misconfigured tests also meant they didn't run pre-merge

@simaoafonso-pwt
Copy link
Contributor Author

yes I think misconfigured tests also meant they didn't run pre-merge

The main problem is that it needs a new tag, since the existing tag failed halfway. The tests pass with that tag.

casperdcl added a commit that referenced this pull request Nov 16, 2021
- follow-up to #57
@simaoafonso-pwt
Copy link
Contributor Author

Oops, I was testing this on a large parser, and I missed skipping the argparse.SUPRESS optional arguments. The positional are correctly skipped.

shtab/shtab/__init__.py

Lines 628 to 634 in 3aca487

for optional_str in optional.option_strings:
log.debug('%s| | %s', log_prefix, optional_str)
if optional_str.startswith('--'):
optionals_double.add(optional_str[2:])
elif optional_str.startswith('-'):
optionals_single.add(optional_str[1:])
specials.extend(get_specials(optional, 'n', optional_str))

It's a matter of gating that with if optional.help != SUPRESS:. Should I open a PR for this oneline change?

@casperdcl
Copy link
Collaborator

Should I open a PR for this oneline change?

yes please do 🙏

simaoafonso-pwt added a commit to simaoafonso-pwt/shtab that referenced this pull request Nov 16, 2021
casperdcl pushed a commit to simaoafonso-pwt/shtab that referenced this pull request Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request shell-tcsh

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for tcsh completion

2 participants