Skip to content

Support running batch files without typing their extension#6278

Merged
rgwood merged 2 commits intonushell:mainfrom
rgwood:fix-code-cmd
Aug 9, 2022
Merged

Support running batch files without typing their extension#6278
rgwood merged 2 commits intonushell:mainfrom
rgwood:fix-code-cmd

Conversation

@rgwood
Copy link
Copy Markdown
Contributor

@rgwood rgwood commented Aug 9, 2022

Description

Fixes #6270. It's once again possible to run a batch script named foo.bat or foo.cmd by typing foo without the file extension.

External command execution on Windows now works like this:

  1. Try to run the external command as a normal executable
  2. If that fails:
    1. Check whether the command name matches a known cmd.exe builtin. If so, run it.
    2. [New in this PR] Check whether which-rs can find an executable in PATH or the cwd. which-rs has logic to include executable file extensions in its search, so it will find foo.cmd given just foo. Run the found executable if its file name differs from the one we already attempted to run.

Tests

Make sure you've done the following:

  • Add tests that cover your changes, either in the command examples, the crate/tests folder, or in the /tests folder.
  • Try to think about corner cases and various ways how your changes could break. Cover them with tests.
  • If adding tests is not possible, please document in the PR body a minimal example with steps on how to reproduce so one can verify your change works.

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --workspace --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace --features=extra to check that all the tests pass

@rgwood
Copy link
Copy Markdown
Contributor Author

rgwood commented Aug 9, 2022

Oops. Made a change that passes clippy on Windows but not Linux, will take a look.

@rgwood
Copy link
Copy Markdown
Contributor Author

rgwood commented Aug 9, 2022

@fdncred as a fellow Windows Guy, does this sounds OK to you?

@rgwood
Copy link
Copy Markdown
Contributor Author

rgwood commented Aug 9, 2022

fdncred confirmed on Discord that this looks OK. Merging now

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.

Windows regression: can no longer run batch files without extension

1 participant