Skip to content

bergkvist/prependpath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

prependpath

Given a (PATH-like) colon-separated string - this tool prepends a value to the string.

Importantly, prependpath is idempotent because it removes existing duplicates of the value in the string.

Usage

prependpath [value] [colon-separated-values]

Example

export PATH=$(prependpath "/my/path/bin" "$PATH")

Install

# Build using the default C compiler
cc prependpath.c -o prependpath -O2 -Wall -Wextra

# Install to /usr/local/bin
sudo cp prependpath /usr/local/bin/prependpath

FAQ

How is this different from just doing the following?

export PATH="/my/path/bin:$PATH"

If /my/path/bin already exists in PATH, it will be removed so that the entry is not duplicated. This makes it convenient for usage in ~/.zshrc or ~/.bashrc as it avoids ever-growing PATH-variables when nesting shells.

About

Prepend values to PATH-like variables idempotently

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages