iterative / shtab

↔️ Automagic shell tab completion for Python CLI applications
https://docs.iterative.ai/shtab
Other
362 stars 35 forks source link

replace all non-word characters with wordify #166

Closed dustinlagoy closed 5 months ago

dustinlagoy commented 6 months ago

Use the regular expression set \W to replace all non-word characters instead of the fixed set [-.\s:] in wordify. I also added a test for subcommands containing slashes in their name as an example. This could be tested more robustly, though that would require more knowledge of some shell completion internals than I currently have.

Closes #165

dustinlagoy commented 6 months ago

Actually I just noticed this does not work in bash (though does in zsh) for commands with slashes in them, as noted in #165. I'm not yet sure if this is something that could be fixed in the generated bash completion script or is a limit of bash itself.

dustinlagoy commented 6 months ago

It looks like the weird command issue I was seeing was due to a conflict with the -o filenames option of the bash complete builtin. That probably reflects more on a poor design choice of using slashes in command names. In any case with this pull request the generated completion script does seem to be valid and works as expected if the -o filenames option is removed. I think this pull request is still worth merging as it will avoid generating incorrect completion code, though in cases like mine may lead to unexpected behavior.

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 88.88%. Comparing base (2be59e4) to head (47e8401).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #166 +/- ## ======================================= Coverage 88.88% 88.88% ======================================= Files 3 3 Lines 360 360 ======================================= Hits 320 320 Misses 40 40 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.