Skip to content

Windows: only shell out to cmd for specific commands#6253

Merged
rgwood merged 1 commit intonushell:mainfrom
rgwood:cmd-specific-commands
Aug 6, 2022
Merged

Windows: only shell out to cmd for specific commands#6253
rgwood merged 1 commit intonushell:mainfrom
rgwood:cmd-specific-commands

Conversation

@rgwood
Copy link
Copy Markdown
Contributor

@rgwood rgwood commented Aug 6, 2022

Description

Nu has behaviour on Windows where, when it can't find an executable on disk, it will "shell out" to cmd.exe. This is because some common shell commands are implemented internally in cmd.exe and do not exist on disk. This PR changes the behaviour so we only shell out for a specific set of known internal commands: ASSOC, DIR, ECHO, FTYPE, MKLINK, START, VER, VOL

Deets

This change is motivated by 2 considerations:

  1. cmd.exe's error messages are not as nice as Nu/Miette errors
  2. Shelling out to cmd.exe makes it difficult to programmatically determine when a command could not be found at all (example)

I read through the full list of internal commands, and determined that those are the only ones likely to be useful in Nu. Here's a spreadsheet with reasoning for each command.

Prior to this PR:
image

After this PR:
image

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.

(no tests added - I think our existing tests cover this)

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

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Aug 6, 2022

The only other built in that I use for troubleshooting sometimes in windows is type but it's rare that I need it. I typical use cat, bat, or open. So, I wouldn't hold up this PR for that. Also, if people complain, it's easy enough to add later if needed.

And I like how this PR enables more nushell's fancy errors. Nice work!

@hustcer
Copy link
Copy Markdown
Contributor

hustcer commented Aug 7, 2022

So can this issue: #4932 be closed?

@rgwood
Copy link
Copy Markdown
Contributor Author

rgwood commented Aug 7, 2022

@hustcer Yes I think so

@CAD97
Copy link
Copy Markdown
Contributor

CAD97 commented Aug 28, 2022

Circling back: it seems assoc/ftype may be useless on Win8 and later: https://stackoverflow.com/a/51727990

I haven't tested, but this does merit investigation; if the builtins don't even function properly anymore, then exposing them through nushell doesn't make any sense.

@rgwood
Copy link
Copy Markdown
Contributor Author

rgwood commented Aug 29, 2022

@CAD97 Good catch, agreed. Are you able to confirm that and submit a PR?

@CAD97
Copy link
Copy Markdown
Contributor

CAD97 commented Aug 29, 2022

I can confirm that assoc/ftype are shoing html associated to IE despite that not being the case on my machine. Opened #6441

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.

4 participants