From 5063e01c12d77a1ac64a061b033ee5b6669ee755 Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Fri, 17 Nov 2023 21:49:07 +0800 Subject: [PATCH] std: add cross platform null-device name (#11070) # Description We have meet a discord discussion about cross platform `null-device`: https://discord.com/channels/601130461678272522/988303282931912704/1165966467095875624 I want the same feature too...And I think it's good enough to add it into `nu-std`. Different to https://github.com/nushell/nu_scripts/pull/649/files, I think named it to `null-device`(the name comes from [wiki](https://en.wikipedia.org/wiki/Null_device)) is better than `null-stream`. --- crates/nu-std/std/mod.nu | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/nu-std/std/mod.nu b/crates/nu-std/std/mod.nu index 7ff38b9d3613..c931817a8826 100644 --- a/crates/nu-std/std/mod.nu +++ b/crates/nu-std/std/mod.nu @@ -335,3 +335,16 @@ export def repeat [ 1..$n | each { $item } } + +# return a null device file. +# +# # Examples +# run a command and ignore it's stderr output +# > cat xxx.txt e> (null-device) +export def null-device []: nothing -> path { + if ($nu.os-info.name | str downcase) == "windows" { + '\\.\NUL' + } else { + "/dev/null" + } +}