Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add path replace-extension to stdlib-candidate #1002

Merged
merged 11 commits into from
Jan 4, 2025
2 changes: 1 addition & 1 deletion stdlib-candidate/nupm.nuon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
description: "Official candidates for Nushell standard library"
documentation: "https://github.com/nushell/nu_scripts/blob/main/stdlib-candidate/std-rfc/README.md"
license: "https://github.com/nushell/nu_scripts/blob/main/LICENSE"
version: 0.4.0
version: 0.4.1
type: "module"
}
30 changes: 30 additions & 0 deletions stdlib-candidate/path/mod.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Replace extension of input file paths.
#
# Note that it doesn't change the file name locally.
#
# # Example
# - setting path ext to `rs`
# ```nushell
# > "ab.txt" | path replace-extension "rs"
# ab.rs
# > "ab.txt" | path replace-extension ".rs"
# ab.rs
#
# - setting a list of input path ext to `rs`
# > ["ab.txt", "cd.exe"] | path replace-extension "rs"
# ╭───┬──────────╮
# │ 0 │ ab.rs │
# │ 1 │ cd.rs │
# ╰───┴──────────╯
# ```
export def replace-extension [
ext: string
] {
let path_parsed = $in | path parse
if ($ext | str starts-with ".") {
$path_parsed | update extension ($ext | str substring 1..) | path join
} else {
$path_parsed | update extension $ext | path join
}
}

Loading
Loading