Skip to content

Commit

Permalink
std: add cross platform null-device name (nushell#11070)
Browse files Browse the repository at this point in the history
# 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`.
  • Loading branch information
WindSoilder authored and hardfau1t committed Dec 14, 2023
1 parent 471084e commit e9c87c4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/nu-std/std/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit e9c87c4

Please sign in to comment.