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

Rename path replace-extension to path with-extension, add with-stem and with-parent #1011

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

132ikl
Copy link
Contributor

@132ikl 132ikl commented Jan 6, 2025

Extends #1002. Renames path replace-extension to path with-extension, in following with other languages (Rust, Python), and adds path with-stem and path with-parent. Also moves the path module into std-rfc so it can be used like use std-rfc/path.

Adds a private helper function, with-field, that with-extension, with-stem, and with-parent can use. These can each be dead simple functions, while giving users more options for path manipulation.

The motivation for separate with-extension, with-stem, and with-parent functions, rather than a more general function like path with is the following:

  • with-extension has special behavior for stripping periods
  • you can tab-complete path with<TAB> to immediately see all the possible options
  • you can't accidentally pass an invalid field to path with
  • there can be separate examples for with-extension, with-stem, with-parent for only the relevant functionality

@132ikl
Copy link
Contributor Author

132ikl commented Jan 6, 2025

I can't request a reviewer for my own PR for some reason, so ping @WindSoilder 😅

@WindSoilder
Copy link
Contributor

Oh, thank you for improving it!

@WindSoilder WindSoilder merged commit 059d74e into nushell:main Jan 6, 2025
1 check passed
# > ["/home/rose/meow", "/home/fdncred/"] | path with-parent "/root/"
# ╭───┬────────────╮
# │ 0 │ /root/meow │
# │ 1 │ /root/spam │
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this output is what you'd get with the input above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops, forgot to copy the updated results back to the example. sorry for slandering your home directory 🤣 fixed in #1013

fdncred pushed a commit that referenced this pull request Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants