Skip to content

feat: add /dev/null handling#1044

Merged
reubeno merged 3 commits intoreubeno:mainfrom
puffnfresh:dev-null
Mar 28, 2026
Merged

feat: add /dev/null handling#1044
reubeno merged 3 commits intoreubeno:mainfrom
puffnfresh:dev-null

Conversation

@puffnfresh
Copy link
Copy Markdown
Contributor

This allows some scripts to run on Windows, which otherwise fail because the /dev/null device does not exist. This is similar to the existing special /dev/fd handling which Brush already contains.

@oech3
Copy link
Copy Markdown
Contributor

oech3 commented Mar 11, 2026

I think it is something Cygwin should care about instead of shell.

@puffnfresh
Copy link
Copy Markdown
Contributor Author

@oech3 is that an argument specifically for /dev/null handling? Brush already does /dev/fd and Bash provides a few more. Where should we draw the line?

I think /dev/null is such a common idiom, it's a shame to have to use a Cygwin environment for many scripts which otherwise run fine on Windows.

@oech3
Copy link
Copy Markdown
Contributor

oech3 commented Mar 11, 2026

Hmm... I did't know that bash has such hacks.

@oech3
Copy link
Copy Markdown
Contributor

oech3 commented Mar 13, 2026

Are you planning to suggest this to upstram bash too?

@reubeno
Copy link
Copy Markdown
Owner

reubeno commented Mar 13, 2026

@puffnfresh thanks for the contribution! It's good to know that some simple changes would unblock more scripts from running natively on Windows under brush.

I also support the idea of being able to use more scripts in a cross-platform way without requiring emulation layers like Cygwin.

Regarding the change, you're right that we have precedent with /dev/fd handling. It wasn't ideal but we were forced to do that because of brush's design of abstracting and decoupling the file descriptors addressable within the shell from the host process's native file descriptors even on platforms like Linux and macOS.

I'm supportive of special handling for /dev/null and similar special files that are ubiquitously accessed in scripts, but we should scope that emulation to the platforms that require it (e.g., Windows).

We use the sys module to abstract platform-specific behaviors. What do you think of adding a new call into the sys module in this code path to give platform-specific code an opportunity to optionally handle special files. We would have the Unix-y platforms implement a no-op, but Windows and others could have a special case there for /dev/null.

This would allow Unix platforms to open the real null file, which is likely to look more consistent with other shells, while still enabling scripts to achieve the desired effect elsewhere.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 13, 2026

Public API changes for crate: brush-core

Added items

+pub const fn brush_core::sys::fs::try_open_special_file(_path: &std::path::Path) -> core::option::Option<core::result::Result<std::fs::File, std::io::error::Error>>

Performance Benchmark Report

Benchmark name Baseline (μs) Test/PR (μs) Delta (μs) Delta %
clone_shell_object 17.28 μs 17.45 μs 0.16 μs 🟠 +0.95%
eval_arithmetic 0.15 μs 0.15 μs -0.01 μs ⚪ Unchanged
expand_one_string 1.67 μs 1.50 μs -0.17 μs ⚪ Unchanged
for_loop 27.63 μs 27.70 μs 0.07 μs ⚪ Unchanged
full_peg_complex 57.93 μs 58.15 μs 0.23 μs ⚪ Unchanged
full_peg_for_loop 6.19 μs 6.21 μs 0.02 μs ⚪ Unchanged
full_peg_nested_expansions 16.75 μs 16.82 μs 0.08 μs ⚪ Unchanged
full_peg_pipeline 4.26 μs 4.31 μs 0.04 μs 🟠 +1.06%
full_peg_simple 1.83 μs 1.85 μs 0.03 μs 🟠 +1.48%
function_call 2.96 μs 2.96 μs 0.01 μs ⚪ Unchanged
instantiate_shell 55.82 μs 54.21 μs -1.61 μs 🟢 -2.89%
instantiate_shell_with_init_scripts 24740.62 μs 25149.68 μs 409.06 μs 🟠 +1.65%
parse_peg_bash_completion 2071.74 μs 2077.14 μs 5.40 μs ⚪ Unchanged
parse_peg_complex 19.76 μs 19.98 μs 0.22 μs 🟠 +1.11%
parse_peg_for_loop 2.00 μs 1.99 μs -0.01 μs ⚪ Unchanged
parse_peg_pipeline 2.12 μs 2.17 μs 0.04 μs 🟠 +2.12%
parse_peg_simple 1.12 μs 1.13 μs 0.00 μs ⚪ Unchanged
run_echo_builtin_command 16.66 μs 16.47 μs -0.19 μs ⚪ Unchanged
tokenize_sample_script 3.40 μs 3.38 μs -0.03 μs ⚪ Unchanged

Code Coverage Report: Only Changed Files listed

Package Base Coverage New Coverage Difference
brush-core/src/shell/fs.rs 🟢 98.21% 🟢 97.39% 🔴 -0.82%
brush-core/src/sys/unix/fs.rs 🟠 61.32% 🟠 62.39% 🟢 1.07%
brush-test-harness/src/comparison.rs 🟢 80.77% 🟢 76.92% 🔴 -3.85%
brush-test-harness/src/execution.rs 🟢 84.04% 🟢 80.85% 🔴 -3.19%
brush-test-harness/src/reporting.rs 🔴 43.66% 🔴 11.62% 🔴 -32.04%
brush-test-harness/src/runner.rs 🟢 82.81% 🟢 82.21% 🔴 -0.6%
brush-test-harness/src/util.rs 🟢 92.31% 🟠 61.54% 🔴 -30.77%
Overall Coverage 🟢 74.89% 🟢 74.36% 🔴 -0.53%

Minimum allowed coverage is 70%, this run produced 74.36%

Test Summary: bash-completion test suite

Outcome Count Percentage
✅ Pass 1583 75.06
❗️ Error 18 0.85
❌ Fail 154 7.30
⏩ Skip 339 16.07
❎ Expected Fail 13 0.62
✔️ Unexpected Pass 2 0.09
📊 Total 2109 100.00

@reubeno reubeno added state: updates requested Pull requests with updates requested platform: windows Issues that specifically relate to Windows platform targets labels Mar 14, 2026
@reubeno reubeno added state: needs review PR or issue author is waiting for a review and removed state: updates requested Pull requests with updates requested labels Mar 26, 2026
Copy link
Copy Markdown
Owner

@reubeno reubeno left a comment

Choose a reason for hiding this comment

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

Change look good to me, @puffnfresh. Thanks for the update!

Looks like the PR checks flagged formatting issues -- and you'll need to rebase/merge latest changes.

@reubeno reubeno added state: updates requested Pull requests with updates requested and removed state: needs review PR or issue author is waiting for a review labels Mar 27, 2026
This allows some scripts to run on Windows, which otherwise fail
because the /dev/null device does not exist. This is similar to the
existing special /dev/fd handling which Brush already contains.
@reubeno reubeno removed the state: updates requested Pull requests with updates requested label Mar 28, 2026
@reubeno reubeno merged commit 139feb3 into reubeno:main Mar 28, 2026
43 checks passed
@reubeno
Copy link
Copy Markdown
Owner

reubeno commented Mar 28, 2026

Merged! Thanks for working on this, @puffnfresh. There was just one last clippy warning that I fixed for you so I could get it merged.

If you end up using this on Windows, would be great to hear what your experience is like / what you're able to do. If you're up for it, feel free to post issues / discussions here on GitHub or on our Discord.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform: windows Issues that specifically relate to Windows platform targets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants