Bash tools to modify $PATH
.
See the latest release for instructions.
path-tools
behaves idempotently. This means that running a command the first
time might change something, but will not change something if you run it a
second time immediately after that.
Results are output to stdout
, $PATH
is never modified.
$PATH
is an implicit parameter, you cannot use path-tools
to modify any
other variable (you can work around this prefixing a command with PATH=...
).
Trailing slashes on paths and literal comparators are removed before comparing.
The functions below are available both as commands and functions (by sourcing path-tools.sh
).
Append ELM
or move it to the end if present.
Append ELM
or move it to the beginning if present.
Insert/move ELM
immediately after the last occurrence of GLOB
.
Append ELM
if no GLOB
matches were found.
GLOB
is compared using [[ ${path%/} = $GLOB ]]
, meaning globs
like /usr/**/bin?(/)
work.
Insert/move ELM
immediately before the first occurrence of GLOB
.
Append ELM
if no GLOB
matches were found.
GLOB
is compared using [[ ${path%/} = $GLOB ]]
, meaning globs
like /usr/**/bin?(/)
work.
Remove all matches for ELM
.
Do nothing if ELM
is not present.
When ENABLE_GLOB = true
(false
is the default) ELM
is compared using
[[ ${path%/} = ELM ]]
, meaning globs like /usr/**/bin?(/)
work.
Returns $? = 0
if ELM
is present, $? = 1
if not.
When ENABLE_GLOB = true
(false
is the default) ELM
is compared using
[[ ${path%/} = ELM ]]
, meaning globs like /usr/**/bin?(/)
work.
Returns $? = 0
if $PATH
is well-formed, $? = 1
if not.
When $PATH
is not well-formed an explanation will written to stderr
.
The following $PATH
invariants are checked:
- Does not contain nul bytes
- Does not contain empty strings (i.e. does not start or end with
:
, and does contain a::
) - Has no duplicate paths