Skip to content

Conversation

@williamthome
Copy link
Contributor

@williamthome williamthome commented Jul 21, 2025

Summary

This PR enhances bash completion for rebar3 by adding file completion support for commands that accept file arguments and fixing completion behavior issues.

Changes

  • File completion for test commands: ct and eunit now complete .erl files and directories
  • File completion for utility commands: completion, shell, and tar now complete files and directories
  • Fixed escaping issues: Removed problematic space-appending logic that caused unwanted backslashes
  • Improved completion options: Changed from -o nospace to -o filenames for better file handling
  • Added test coverage: New check_bash_file_completion test validates file completion functionality in CI

Examples

Before (no file completion):

$ rebar3 ct --suite test/<Tab>
# No completion - user had to type full paths manually

$ rebar3 eunit --dir <Tab>
# Only showed flags, no test files

After (with file completion):

$ rebar3 ct --suite test/<Tab>
test/my_app_SUITE.erl  test/helper_tests.erl  test/integration/

$ rebar3 eunit --dir <Tab>
test/unit_tests.erl  src/my_module.erl  test/

$ rebar3 completion --file <Tab>
completion.bash  scripts/  config/

$ rebar3 shell --env-file <Tab>
.env  config.sys  scripts/

Escaping fix:

# Before: unwanted backslashes
$ rebar3 ct --su<Tab> → $ rebar3 ct --suite\ 

# After: clean completion
$ rebar3 ct --su<Tab> → $ rebar3 ct --suite 

Testing

To test these changes:

  1. Build and install the updated rebar3:

    ./bootstrap
    ./rebar3 local install
  2. Generate the new completion file:

    ./rebar3 completion --file completion.bash
  3. Source the completion in a new terminal:

    source _build/default/completion.bash
  4. Test file completion:

    # In a project with test files
    rebar3 ct --suite test/<Tab>
    rebar3 eunit --dir <Tab>
    rebar3 completion --file <Tab>
    rebar3 shell --env-file <Tab>
  5. Run the test suite:

./rebar3 ct --suite apps/rebar/test/rebar_completion_SUITE

The test automatically runs in CI and verifies:

  • File completion logic is present for ct and eunit commands
  • .erl file filtering works correctly
  • Directory completion is included
  • Other file-accepting commands (completion, shell, tar) are handled
  • Fallback completion logic is preserved

Backward Compatibility

This change is backward compatible - existing completion behavior is preserved while adding new file completion capabilities.

- Add file completion for ct and eunit commands (.erl files and directories)
- Add file completion for completion, shell, and tar commands (all files)
- Remove problematic space-appending logic that caused backslash escaping
- Change complete option from -o nospace to -o filenames for better file handling

This improves the user experience by allowing tab completion of test files
and other file arguments without unwanted backslashes or spacing issues.
- Add check_bash_file_completion test to validate generated completion script
- Update existing test to expect new -o filenames completion option
- Test verifies .erl file completion, directory completion, and fallback logic
- Ensures file completion changes are covered by automated testing
@ferd ferd merged commit ec0caee into erlang:main Jul 23, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants