3 stable releases
Uses new Rust 2024
| 1.0.8 | Nov 23, 2025 |
|---|---|
| 1.0.0 | Sep 16, 2025 |
#218 in Configuration
14KB
55 lines
path-munge
This utility is designed to help with managing PATH-type shell variables.
For example, given
$ echo $MANPATH
:/usr/local/man:/home/andrew/.local/share/man
we can prepend directories via
$ path-munge MANPATH prepend force a b c
a:b:c:/usr/local/man:/home/andrew/.local/share/man
or append then via
$ path-munge MANPATH append force a b c
/usr/local/man:/home/andrew/.local/share/man:a:b:c
Note that extra path-separator characters are trimmed from the result.
Usage
To use it in your .bashrc, you would need to use it as part of an expansion,
since path-munge never modifies the environment itself.
For example, to prepend /opt/bin and /foo/bar to your path, use
PATH="$(path-munge PATH prepend force /opt/bin /foo/bar)"
In addition to the prepend and append options, you can also use keep
to retain the precedence of a path if it already exists, or use force to
remove its existing precedence and replace it with the new one.
Installation
Install with cargo:
cargo install path-munge
or download a binary from the releases page.
MANPATH Warning
Note that MANPATH is a bit special. path-munge removes prefix, postfix, and double colons.
However, the man manual page, under "SEARCH PATH" has an interesting note:
If the value of
$MANPATHstarts with a colon, then the default search path is added at its start. If the value of$MANPATHends with a colon, then the default search path is added at its end. If the value of$MANPATHcontains a double colon (::), then the default search path is inserted in the middle of the value, between the two colons.
What this means is that unless you add back a leading or trailing colon when setting MANPATH, you will be unable to search the default system MANPATH!
Dependencies
~1–1.5MB
~27K SLoC