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
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
convert Convert between unix and windows paths
info Print information about paths
depth Number of components before the last component.
help Print this message or the help of the given subcommand(s)
Options:
-x, --as-unix Parse paths as unix paths
-w, --as-windows Parse paths as windows paths
-u, --as-url Parse paths as URLs
-h, --help Print help
-V, --version Print version
File Components:
ext File extension
stem File stem
prefix File prefix (before first dot)
name File name
disk Disk of a windows path
winprefix Windows path prefix
URL Components:
scheme URL scheme (http, https, etc.)
host Hostname
port Port number
path URL path
query Query string
frag Fragment identifier
user Username
pass Password
origin scheme://host:port
tld Top-level domaint
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 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.
Currently theres baked-in redundancy removal within the parser, such as ././/.// is just parsed as ./. I want this to be opt-in behavior.
There's also default detection between windows and unix that I think could be improved.
Changelog
0.8.0
- Add URL parsing with
-u/--as-url flag
- Add URL components:
scheme, host, port, path, query, frag, user, pass, authority, origin, tld, ip, ipv4, ipv6
- Add
info command to print detailed path information
--json flag to output as JSON instead of YAML
- Add
is url question to check if a path is a URL
- Add
winprefix component for full Windows path prefix (UNC, verbatim, etc.)
- Change
-u short flag to mean --as-url; unix paths now use -x/--as-unix
- Remove
parent component
- Remove nth component indexing (e.g.,
0, -1)
- Remove
normalize command
- Remove
-n/--normalize flag
- Remove
is normalized question
0.7.0
- Normalize flag
-n that can apply normalization to the paths before any command
- Flags to force parsing paths as windows
-w or as unix -u paths
- Add
is normal command which checks if a path string is normalized
- Add
depth command which counts the number of components before the last
- Add
disk component for Windows paths with disk prefix
0.6.0
- Specify nth component using negative indicies to count backwards,
-1 for last component, etc.
- Add
normalize command that removes .. and . from path appropriately
- Add
convert command to convert between Windows and unix paths
0.5.0
- Rename
replace to set
- 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
0.4.0
- Remove
--remove and --replace args with delete and replace commands
- Add
get command (default behavior)
- Components are now arguments to
get, delete, and replace
- Specify nth component by using number,
0 for first component, etc.
- Remove
first component
0.3.0
- Add
first command
- Add
--remove and --replace arguments for every command
- Remove
rmext command
0.2.0
- Show help by default
- Read from stdin, all at once
- Allow passing multiple file paths as args (not stdin)
- Add
rmext command
0.1.0
- Add
ext, stem, prefix, name, parent commands.