Project are different from one another. And so our environment, we might be developing an application on our local machine with certain environment variables like debug level APKs, or memory size. Then we want to deploy the application to a staging or production server, which has other values for the same environment variables. A tool that comes in handy for loading environment on the fly is auto M. To install it, we go to the official GitHub page and follow the instructions. First, we will clone the project in our home directory. Then we add this line to our config file so that every time that shell starts auto ml is loaded by default.
Now let's create an example workplace with two imaginary projects, project one and project two. We open an environment file in Project one. And let's imagine that project one uses an environment variable called env, which we will set to death. Now let's do the same thing for project two but with a different value for m 287. Save and close both files. And now we CD in the project folder, and we see the following message.
Oh, yeah, hit yes to load the file. And this happens every time a new environment file is sourced. Now if we grab the environment for the end variable, which A seat present and with the value of death now let's change the directory to project two, we see that the same warning message is issued. And when we grep for the N variable, we now see that its value is QA. If you leave this folder, the environment variable is still defined and will be defined under some other script overwrite it, or when the current session is closed. The End file is sourced even if we CD into a directory deeper inside project one.
Now let's look at a more complex example for project one. Let's say we want to get the version from package JSON. And we also want to use a variable called compose file that will specify different files For Docker compose Docker users know what it's all about. But if you don't Google the time and for this to take effect, we need to first copy a package JSON file and test that the cat command works. Everything seems fine. So let's CD into our folder.
And as you can see the environment variables have been set. Auto AMS can really come in handy and is not limited to just exporting environment variables. You can do stuff like a short reminder when entering a certain project or running a poll or updating the look and feel of the terminal so that a distinct feel is given for each project.