nushell/crates/nu-command/src
Hayden Frentzel b33f4b7f55
Run scripts of any file extension in PATHEXT on Windows (#15611)
# Description
On Windows, I would like to be able to call a script directly in nushell
and have that script be found in the PATH and run based on filetype
associations and PATHEXT.

There have been previous discussions related to this feature, see
https://github.com/nushell/nushell/issues/6440 and
https://github.com/nushell/nushell/issues/15476. The latter issue is
only a few weeks old, and after taking a look at it and the resultant PR
I found that currently nushell is hardcoded to support only running
nushell (.nu) scripts in this way.

This PR seeks to make this functionality more generic. Instead of
checking that the file extension is explicitly `NU`, it instead checks
that it **is not** one of `COM`, `EXE`, `BAT`, `CMD`, or `PS1`. The
first four of these are extensions that Windows can figure out how to
run on its own. This is implied by the output of `ftype` for any of
these extensions, which shows that files are just run without a calling
command anyway.
```
>ftype batfile
batfile="%1" %*
```
PS1 files are ignored because they are handled as a special in later
logic.

In implementing this I initially tried to fetch the value of PATHEXT and
confirm that the file extension was indeed in PATHEXT. But I determined
that because `which()` respects PATHEXT, this would be redundant; any
executable that is found by `which` is already going to have an
extension in PATHEXT. It is thus only necessary to check that it isn't
one of the few extensions that should be called directly, without the
use of `cmd.exe`.


There are some small formatting changes to `run_external.rs` in the PR
as a result of running `cargo fmt` that are not entirely related to the
code I modified. I can back out those changes if that is desired.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
Behavior for `.nu` scripts will not change. Users will still need to
ensure they have PATHEXT and filetype associations set correctly for
them to work, but this will now also apply to scripts of other types.
2025-04-24 09:10:34 -05:00
..
bytes fix range bugs in str substring, str index-of, slice, bytes at (#14863) 2025-01-30 06:50:01 -06:00
charting Add Filesize type (#14369) 2024-11-29 21:24:17 +00:00
conversions feat: duration from record (#15600) 2025-04-19 18:29:12 -05:00
database Refactor I/O Errors (#14927) 2025-01-28 16:03:31 -06:00
date Bugfix: datetime parsing and local timezones (#15544) 2025-04-11 07:48:39 -05:00
debug add --raw-value option to debug command (#15581) 2025-04-17 12:12:07 -05:00
env Add job tags (#15555) 2025-04-21 20:08:00 +08:00
experimental Add job tags (#15555) 2025-04-21 20:08:00 +08:00
filesystem Add --follow-symlinks flag to glob command (fixes #15559) (#15626) 2025-04-23 10:47:48 -05:00
filters Fix #13546: Outer joins incorrectly removing unmatched rows (#15472) 2025-04-22 07:19:08 +08:00
formats Fix #14660: to md breaks on tables with empty values (#15631) 2025-04-24 09:09:48 -05:00
generators seq date: generalize to allow any duration for --increment argument (#14903) 2025-01-25 13:24:39 -06:00
hash add binary as input to hash commands (#13923) 2024-09-25 16:47:52 +08:00
help Rework operator type errors (#14429) 2025-02-12 20:03:40 -08:00
math Fix clippy (#15489) 2025-04-06 09:49:28 +08:00
misc More precise ErrorKind::NotFound errors (#15149) 2025-02-22 11:42:44 -05:00
network Fix clippy (#15489) 2025-04-06 09:49:28 +08:00
path Replace some PipelineMismatch by OnlySupportsThisInputType by shell error (#15447) 2025-04-07 12:25:27 +02:00
platform Allow spreading arguments of kill command (#15558) 2025-04-13 07:50:04 -05:00
random Update rand and rand_chacha to 0.9 (#15463) 2025-04-01 07:15:39 -05:00
removed refactor: rename subcommand structs (#15309) 2025-03-14 02:00:35 +01:00
shells Jobs (#14883) 2025-02-25 12:09:52 -05:00
stor Run-time pipeline input typechecking tweaks (#14922) 2025-02-02 15:51:47 -05:00
strings bugfix: str join outputs dates consistently (RFC2822 when possible) (#15629) 2025-04-24 08:32:29 -05:00
system Run scripts of any file extension in PATHEXT on Windows (#15611) 2025-04-24 09:10:34 -05:00
viewers Refactor I/O Errors (#14927) 2025-01-28 16:03:31 -06:00
default_context.rs Add job tags (#15555) 2025-04-21 20:08:00 +08:00
example_test.rs Implementing ByteStream interuption on infinite stream (#13552) 2025-01-11 13:28:08 -08:00
lib.rs Start to Add WASM Support Again (#14418) 2024-11-30 07:57:11 -06:00
progress_bar.rs Cut down unnecessary lint allows (#14335) 2024-11-15 19:24:39 +01:00
sort_utils.rs Remove deprecated commands (#14726) 2025-01-07 07:37:51 +08:00