Unlimited WordPress themes, graphics, videos & courses! Unlimited asset downloads! From $16.50/m
by
Lessons:28Length:1.7 hours
Speedy workflows with atom.io
  • Overview
  • Transcript

7.4 Bash Profile

Our boilerplate process is almost perfect. We have everything down to one command, but the script needs to run wherever we need it to. We need to know the path to the script at the moment. By moving the script from the bash profile, we can access it from anywhere. You can easily get to your bash profile from anywhere in the terminal. You can type atom ~/.bash_profile. And when we hit Enter, this pulls up our bash profile. If you're having any trouble pulling up your bash profile, then create a blank one at that location. This is currently some of the global code that runs in my bash profile. It's responsible for letting me know what GitHub branch I'm on, as well as doing some coloring. To run this bash script, we're going to need a function. Within this function, we just need to paste in our script. We can access this function from the console by just typing in its name. Make sure to reset the terminal every time you make changes to your bash profile. Now, we can just call up this simple node server function and we'll pass in our name. And it generates out our boilerplate and we can do this from any folder because it's in our bash profile. You might find this calling simple node server to be a little long. You can actually alias is out to a smaller name. An alias is essentially a short cut. You can create one by specifying the keyword alias, then the shortcut name. In this case, we'll call it simns. And we'll set that equal to the function name wrapped in a string. Now we'll save and restart our terminal. Now we're in a new place in the terminal, and if we call simns, and pass through the name. Our script will generate out the new project. Just as always, we can type in node server, and on the port 3000 our app spins up just as we expect it to. So using the bash profile gives us access to our scripts at a global level. And we can call this by using the function name, or if we want to shorten it out we can use an alias. This gave us a reproducible and automated way to create out new projects. What's awesome about this process is that it can be done with many different examples. You just need to create a GitHub repo and then a script to automate the process. So think about all of the common pieces of code you write everyday. Then think about how much faster you could write them if there was a bash script.

Back to the top