diff options
author | Joe Hunkeler <jhunk@roden.local.stsci.edu> | 2021-05-04 17:34:38 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2021-05-04 21:14:16 -0400 |
commit | ea6e2613aca23c84373e686d739498969062f79e (patch) | |
tree | ba9cf39409056cad0b65a4ee953856230e73196b /README.md | |
download | cleanpath-ea6e2613aca23c84373e686d739498969062f79e.tar.gz |
Initial commit
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..38ebcbb --- /dev/null +++ b/README.md @@ -0,0 +1,71 @@ +# cleanpath + +`cleanpath` is a utility that filters unwanted elements from an environment variable. + +# Installation + +```shell +$ git clone https://github.com/jhunkeler/cleanpath +$ cd cleanpath +$ mkdir -p build +$ cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/.local +$ make install +``` + +# Usage + +```shell +usage: cleanpath [-hVelrsv] [pattern ...] + --help -h Displays this help message + --version -V Displays the program's version + --exact -e Filter when pattern is an exact match (default) + --loose -l Filter when any part of the pattern matches + --regex -r Filter matches with (Extended) Regular Expressions + --sep [str] -s Use custom path separator (default: ':') + --env [str] -E Use custom environment variable (default: PATH) +``` + +# Example + +A typical MacOS path with Macports installed: +```shell +/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin +``` + +## Remove MacPorts from the PATH + +### Exact match (default) +```shell +$ cleanpath /opt/local/bin /opt/local/sbin +/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin +``` + +### Loose match +```shell +$ cleanpath -l /opt/local +/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin +``` + +### Regex match + +```shell +$ cleanpath -r ^/opt/local/.* +/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin +``` + +## Modifying other environment variables + +```shell +$ TESTVAR=a:b/c:d/e:f +$ cleanpath -E TESTVAR -s / -l c +a:b/e:f +``` + +## Using cleanpath in a script + +```shell +#!/usr/bin/env bash +# Remove MacPorts and Fink +PATH=$(cleanpath -r '^/opt/local/.*' '^/opt/sw/.*') +export PATH +``` |