| Crates.io | pathmut |
| lib.rs | pathmut |
| version | 0.7.0 |
| created_at | 2022-12-02 22:29:41.760667+00 |
| updated_at | 2025-03-27 02:15:16.272002+00 |
| description | Command line utility for manipulating path strings |
| homepage | |
| repository | https://github.com/rutrum/pathmut |
| max_upload_size | |
| id | 728665 |
| size | 86,736 |
pathmut is a path string manipulation utilityThis 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
Mutate path strings
Usage: pathmut [OPTIONS] [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
normalize Normalize a file path
convert Convert between unix and windows paths
depth Number of components before the last component.
help Print this message or the help of the given subcommand(s)
Options:
-n, --normalize Normalize the path first
-u, --as-unix Parse paths as unix paths
-w, --as-windows Parse paths as windows paths
-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
disk Disk of a windows path
n Ordinal of the nth component
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
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:
I should be able to work with multiple paths:
Why stop at paths? A command line utility built to mutate URIs like "scheme://user:pass@sub.domain.com/route?query=param#anchor" would have an almost identical API, and would even overlap with some path functionality. In the future, this library will expand to include URIs as well.
-n that can apply normalization to the paths before any command-w or as unix -u pathsis normal command which checks if a path string is normalizeddepth command which counts the number of components before the lastdisk component for Windows paths with disk prefix-1 for last component, etc.normalize command that removes .. and . from path appropriatelyconvert command to convert between Windows and unix pathsreplace to setreplace command, which does not change paths when the component does not existis 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 pathshas command for checking if a path component exists--remove and --replace args with delete and replace commandsget command (default behavior)get, delete, and replace0 for first component, etc.first componentfirst command--remove and --replace arguments for every commandrmext commandrmext commandext, stem, prefix, name, parent commands.