Path Command Enhancement Project#2742
Conversation
|
These sounds cool! Thanks! |
|
Seconded! I like these |
d39c754 to
e369821
Compare
This adds a lot of redundancy to non-relevant subcommands such as type, exists or expand.
`path expand` is still broken but otherwise seems to fix all examples on Windows
Also disable example tests for path expand. Failed caconicalization (e.g., due to path not existing) returns the original path so the examples always fail.
35fed8e to
039decf
Compare
Wouldn't run on minimal due to useing optional dependency. The test success was also deending on the presence of home dir on the testing machine which might not be completely robust.
|
Alright, path handling turned out to be a little rabbit hole. The commands mostly respect the I think the path handling would deserve some consistency revamp so it behaves the same way on all platforms but I'll leave it for a further discussion / PR. |
|
This is great, thanks for putting it together! |
|
and agreed, we'll want to circle back and improve the path handling a bit more. We can do that in a future PR and land this one, as I think these improvements stand on their own. |
Description
The aim of this PR is to add a couple of options enhancing the capabilities of the
pathsubcommands. More specifically, it makes it easier to mass-rename files and their locations without an excessive use ofbuild-stringchains. I found both nu and traditional Unix tools (such as dirname or basename) too verbose when I was encoding and moving tens of thousands images in tens of different folders all over the place.Changes
path basename
--replace <string>option to replace the basename instead of returning itecho foo/bar/baz.txt | path basename -r spam.mdwould returnfoo/bar/spam.md)path dirname
-n <int>option to specify how many levels up to returnecho foo/bar/baz.txt | path dirname -n 2would returnfoo)--replace <string>option to replace the dir instead of returning it (respecting the-noption)echo foo/bar/baz.txt | path dirname -n 2 -r eggswould returneggs)path extension
--replace <string>option to replace the extension instead of returning itecho test.txt | path extension -r mdwould returntest.md)path filestem
--replace <string>option to replace the filestem instead of returning itecho foo/bar/baz.txt | path basename -r spamwould returnfoo/bar/spam.txt).tar.gzout_<whatever>misc
...args: optionally operate by pathwith...args: optionally operate by column pathin subcommands desctiprions