Skip to content

Instantly share code, notes, and snippets.

@willurd willurd/
Last active Nov 29, 2016

What would you like to do?
Manage your PATH with a nice, one-directory-per-line file, rather than a gargantuan blob of colon-delimited text.
# Read the contents of ~/.path into $PATH, if ~/.path exists. ~/.path should be a file
# consisting of one path on each line, such as:
# ~$ cat ~/.path
# # vim: ft=sh
# ~/usr/bin
# /opt/local/bin
# ... etc ...
# Note that comments begin with a hash (#).
# awk-fu courtesy of pickledspiders:
# awk line fix courtesy of cpitchford:
if [ -e "$DOT_PATH_FILE" ]; then
export PATH=$PATH:`awk '/^[^#]/{printf "%s",(++x!=1?":":"")$0}' $DOT_PATH_FILE`

This comment has been minimized.

Copy link

necrophcodr commented May 25, 2013

Using this right now, and this method of path management is much more pleasant than keeping track of PATH exports.


This comment has been minimized.

Copy link
Owner Author

willurd commented May 25, 2013

Sooooo much more pleasant :)


This comment has been minimized.

Copy link

alnorris commented May 26, 2013

Nice one!


This comment has been minimized.

Copy link

vodik commented May 27, 2013

Probably better to change the first line to this:


So someone can override the loopup by setting DOT_PATH_FILE before calling the script.

This is a litte better for the rest:

if [[ -e "$DOT_PATH_FILE" ]]; then
    export PATH="$PATH:$(awk '/^[^#]/{printf "%s",(++x!=1?":":"")$0}' "$DOT_PATH_FILE")"

And for what its worth, ~ isn't a valid character in ~/.path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.