Skip to content

fix: complete path arguments before later options - #248

Merged
casperdcl merged 4 commits into
tqdm:mainfrom
tomatotomata:codex/fix-bash-middle-command
Aug 12, 2026
Merged

fix: complete path arguments before later options#248
casperdcl merged 4 commits into
tqdm:mainfrom
tomatotomata:codex/fix-bash-middle-command

Conversation

@tomatotomata

Copy link
Copy Markdown
Contributor

What changed

When Bash is completing a custom path argument and the next token already starts with -, the generated completer now keeps the path completer active. This covers editing a command such as ... -d -w and prevents the later option from being inserted as the path value.

Verification

  • python -m compileall -q shtab
  • git diff --check
  • Added a regression test covering a directory argument followed by another option.

I could not run the full pytest suite on this Windows checkout because the repository's POSIX pty test helper requires termios, and the local environment also has incompatible pytest recording plugins. Let me know what you think.

@casperdcl casperdcl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unsure what your intention is. Is it related to #116?

In any case the test is failing.

@tomatotomata
tomatotomata force-pushed the codex/fix-bash-middle-command branch from 7fc7894 to 5df353b Compare August 10, 2026 17:23
@tomatotomata

Copy link
Copy Markdown
Contributor Author

I traced this back to #116. The generated Bash function was keeping the path completer active, but it was still passing the already-typed option token (-w) into that completer, so it could not list the directory entries.

Commit 5df353b keeps the path completer selected and passes an empty word when the current token starts with -. That makes the middle-of-command case complete the pending -d path argument while leaving later options in place. The existing regression now returns folder for COMP_WORDS=(test -d -w); COMP_CWORD=2.

Validation on this checkout:

  • focused Bash completion scenario: passed
  • python -m compileall -q shtab: passed
  • git diff --check: passed

The full pytest suite still cannot start on this Windows checkout because its POSIX pty helper imports termios. Let me know what you think of this narrower fix.

@casperdcl casperdcl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this currently breaks examples/pathcomplete.py:

pathcomplete -<TAB>   # doesn't list --options
pathcomplete . -<TAB> # correctly lists --options

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.13%. Comparing base (22cc55d) to head (65ca5cc).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #248   +/-   ##
=======================================
  Coverage   85.13%   85.13%           
=======================================
  Files           3        3           
  Lines         471      471           
  Branches       92       92           
=======================================
  Hits          401      401           
  Misses         39       39           
  Partials       31       31           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tomatotomata

Copy link
Copy Markdown
Contributor Author

I reproduced the regression in the generated Bash state machine. The path completer should still win when an option token is actually the value for a pending option argument, but after a positional path is complete the user should be able to start a new - option. I adjusted that branch to distinguish those two states and added a regression test for COMP_WORDS=(test . -), while keeping the existing middle-of-command path test. The generated Bash script passes bash -n, Python compilation and git diff --check pass, and the fix is on d35ce54. Let me know what you think.

@casperdcl
casperdcl force-pushed the codex/fix-bash-middle-command branch from d35ce54 to cd06afb Compare August 12, 2026 18:45
@casperdcl
casperdcl force-pushed the codex/fix-bash-middle-command branch from cd06afb to 65ca5cc Compare August 12, 2026 18:56
@casperdcl casperdcl linked an issue Aug 12, 2026 that may be closed by this pull request

@casperdcl casperdcl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Fixes #116

@casperdcl
casperdcl merged commit 116e9b4 into tqdm:main Aug 12, 2026
6 of 7 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.

[Bug] bash: fix tab completion mid-command

2 participants