Make Your Terminal Work For You
One of the things I learned from reading Atomic Habits was the importance of 1% improvements. It can be very hard to find the single actions that will make you 20% or 30% better at your job, but if you can find small areas to make 1% improvements everyday, you'll end your year in a much better place.
I want to share some of my 1% improvements for working with terminals. As a software engineer, I spend a lot of my time on the terminal running CLI (command line interface) applications like: npm, git, and ssh.
What is a Terminal?
Simply put, a terminal is a text-based way to interact with software. In Windows you have applications like Command Prompt, PowerShell, and Windows Terminal that allow you to interact with terminal. If you're a macOS user or Linux user, the terminals are simply called: terminal.
If you use a text editor like Visual Studio Code, they also provide you a terminal to interact with from within the editor itself.
If you've ever messed around with Windows' command prompt and the macOS terminal, you might've noticed a slight difference in the commands you can run. For example, a command like ls works in macOS to list files in a directory but doesn't work on the Windows command prompt.
Here are a few cheatsheets for the popular terminal environments:
Windows Command Prompt
macOS / Linux (Bash)
A profile is a file that contains the scripts that your terminal will run when you start the terminal. The formatting of these files varies across terminals, but the popular naming convention is calling them an "rc" file (rc = "run commands").
These files are handy because any customizations you want to use every time you open your terminal can be saved here! I personally use mine to set aliases and colors for my editors. Others go above and beyond with theirs though.
If you want to learn more about creating these files check out the tutorials for the following environments:
Windows Command Prompt
macOS / Linux (Bash)
Environment variables are simply variables that are able to be accessed from within your terminal. Something I do with my environment variables it set the paths for common folders.
By defining these environment variables, I'm able to simply type the following command to navigate to where I keep my source files:
Some environment variables are set by the operating system and can be used when writing scripts. You can reference things like the user currently logged in, the home directory, and the path that the terminal references to execute commands.
You can read this chapter on Environment Variables to learn more.
In our day-to-day lives, there are times we have to run longer commands that take awhile to type out. If you're a node developer you've likely done this a few times:
rm -rf node_modules/ npm install
Or if you use GitHub you've probably done:
git fetch origin git merge origin develop
If you find yourself repeating commands over and over again, you can create what's called an alias. It's basically a shortcut for a longer command.
alias npmi='npm install' alias nuke='rm -rf node_modules && npmi`
In the above example, I created an alias called "npmi" which simple runs "npm install". Then in the next one, I created a "nuke" alias which removes the node_modules directory and then calls the npmi alias to reinstall node.
This is something I find myself doing... a lot.
A thing to note about aliases, if you don't save the command to a file it will only work for the active session. So if you create an alias, you can use it but as soon as you open up a new terminal it will be gone.
If you're frequently traversing long directories, consider creating an alias to navigate to them. You can create this alias and save it in your Profile (depending on your environment) so that you have access to it every time you run your terminal.
Many terminals support autocomplete and that's something that I've found helpful when creating a bunch of "cd*" aliases. I only type a few characters and then hit tab and then it will run through the aliases I've created.
Once you feel more comfortable with terminals, consider installing plugins and tools. On my personal computer I use oh-my-fish which uses the fish shell. It provides extensions for some of the developer work I do such as showing my GitHub branches right on the terminal when I'm in a repository.
Until writing this post, I really hadn't thought much about my terminal setups. I set them up a few months or years ago (depending on the computer) and anytime I change jobs or acquire a new machine I basically just set it up like I have it on other machines.
Now that I've got a bunch of downtime I really want to dive into my terminal environments and see what tweaks I can make that will make things a little bit faster for me.