Skip to content

Commit b6b76d1

Browse files
committed
Reapply "add path extension func to stdlib-candidate"
This reverts commit 43d1224.
1 parent 43d1224 commit b6b76d1

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

stdlib-candidate/nupm.nuon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
description: "Official candidates for Nushell standard library"
44
documentation: "https://github.com/nushell/nu_scripts/blob/main/stdlib-candidate/std-rfc/README.md"
55
license: "https://github.com/nushell/nu_scripts/blob/main/LICENSE"
6-
version: 0.4.0
6+
version: 0.4.1
77
type: "module"
88
}

stdlib-candidate/path/mod.nu

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Update extension of input files.
2+
#
3+
# # Example
4+
# - setting path ext to `rs`
5+
# ```nushell
6+
# > "ab.txt" | path extension "rs"
7+
# ab.rs
8+
# > "ab.txt" | path extension ".rs"
9+
# ab.rs
10+
#
11+
# - setting a list of input path ext to `rs`
12+
# > ["ab.txt", "cd.exe"] | path extension "rs"
13+
# ╭───┬──────────╮
14+
# │ 0 │ ab.rs │
15+
# │ 1 │ cd.rs │
16+
# ╰───┴──────────╯
17+
# ```
18+
export def extension [
19+
ext: string
20+
] {
21+
let path_parsed = $in | path parse
22+
if ($ext | str starts-with ".") {
23+
$path_parsed | update extension ($ext | str substring 1..) | path join
24+
} else {
25+
$path_parsed | update extension $ext | path join
26+
}
27+
}
28+

0 commit comments

Comments
 (0)