A quick and dirty script for loading/appending to PATH
Oftentimes when I write install scripts i have to go looking for a path and its presence to avoid duplication, parsing the .bashrc and .profile scripts .
This is tedious, and prone to issues.
If we could have a basic utility that already took care of this as a default item in the system, it would be handy.
This gist contains one such implementation, in Python 3.
I intend to re-write this in Rust as an excercise, for learning.
The following are the requirements I set out for myself, for reference. If anyone would like to have a go and "standardize" on the excercise, do feel free. It would be neat to get it into a major distro, but I'm not holding my breath.
~/.PATH
file contains user's paths, one per line. Lines may be empty. Lines starting with '#' are comments and are to be skipped- command may take the argument
load
to print a path-notation of paths, each separated by colon - command may take the arguments
add DIR_PATH
which will add the path to the end of~/.PATH
- command may take the argument
version
which will print the version string alone - any other argument form causes help to be printed, and exits with error code
- any error should cause print out of error message, without printing stack traces or other debugging noise
In my case, I also check for duplication, though this is not a requirement. I also print the new path notation after adding, again this is not a requirement.