5 releases (breaking)
0.5.0 | Feb 1, 2025 |
---|---|
0.4.0 | Dec 23, 2024 |
0.3.0 | Dec 5, 2022 |
0.2.0 | Dec 4, 2022 |
0.1.0 | Dec 2, 2022 |
#221 in Text processing
132 downloads per month
47KB
1K
SLoC
pathmut
is a path string manipulation utility
This was made because I'm tired of resorting to basename
, dirname
, cut -d. -f1
or whatever other random core util to just extract some information from paths.
Important to know this utility only works with path strings and doesn't touch the file system whatsoever.
$ pathmut
Mutates path strings
Usage: pathmut [COMMAND or COMPONENT]
Commands:
get Read a path component [default]
delete Remove a path component
replace Replace an existing path component
set Set a path component
has Check if a path component exists
is Ask questions about a file path
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help information
-V, --version Print version information
Components:
ext File extension
stem File stem
prefix File prefix
name File name
parent Parent of the file or directory
n Ordinal of the nth component
Installation
For now, you have to build from source. The package is available on crates.io and can be installed with cargo
.
cargo install pathmut
You can also build using nix
if you have flakes enabled.
nix shell github:rutrum/pathmut
Future Development
I'd like this to be the all in one tool for manipulating path strings. This tool should never touch or look at the actual filesystem, which means it shouldn't be able to answer if a path exists, if something is a file, create files, etc.
I should be able to ask questions about path strings, like the following:
- Is the path valid, if it did exist?
- What is the depth of the path?
I should be able to manipulate paths as a whole:
- I should canonicalize a path (remove redundant
../
and./
)
I should be able to work with multiple paths:
- Does path A begin with path B?
- Does path A end with path B?
- Is path B contained with path A?
- Join path A and path B together.
Changelog
v0.5.0
- Rename
replace
toset
- Add
replace
command, which does not change paths when the component does not exist - Windows and unix path support, independent of native OS
- Add
is
command which tests if paths are relative, absolute, windows, or unix--print
flag to print true/false instead of changing exit code--any
and--all
flags for testing multiple paths
- Add
has
command for checking if a path component exists
v0.4.0
- Remove
--remove
and--replace
args withdelete
andreplace
commands - Add
get
command (default behavior) - Components are now arguments to
get
,delete
, andreplace
- Specify nth component by using number,
0
for first component, etc. - Remove
first
component
v0.3.0
- Add
first
command - Add
--remove
and--replace
arguments for every command - Remove
rmext
command
v0.2.0
- Show help by default
- Read from stdin, all at once
- Allow passing multiple file paths as args (not stdin)
- Add
rmext
command
v0.1.0
- Add
ext
,stem
,prefix
,name
,parent
commands.
Dependencies
~3–12MB
~142K SLoC