Sunday, December 18, 2016

command line - Best practice for Windows PATH/environment variables managing?


Right now, it's such a mess. Every time I install a new program that does something trivial in the command line, I have to add it to the path. In fact, I'm developing on Ruby and even gems (plugins/extensions) sometimes have their own executables, and are stored in different folders and I end up having to add several paths per application, as well. It's gotten to the point that I am pushing thirty paths in my PATH environment variable.


I'm cautious to copying and pasting them to a home folder of sorts and setting path to that; it just feels wrong. Is there an established best practice that I am missing?


Answer



A number of small self-contained utilities reside in my %UserProfile%\Apps folder, such as archivers and the like. Then there are a number of batch files I wrote and frequently use which reside in %UserProfile%\Batches. For the rest, I just add them to the PATH, which is either done by an installer or with


setx PATH "%PATH%;%CD%"

from the appropriate directory. The number of paths there should probably only ever become an issue if the contents get too long (there are length limits for environment variables).


You can (and I sometimes do) write small wrapper batch files for such programs. Simply copying/hardlinking/symlinking the executable into another directory will likely not work on Windows but you can easily create a batch file, for example for the program Foo:


@"%ProgramFiles%\Foosoft Foo\foo.exe" %*

and you can then add the folder where you store those batch files to your PATH.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...