Customize your terminal with aliases

To beginners, the terminal looks like a scary place. I remember what I was thinking when I was watched developers use the dark looking box with text. It felt complicated and there was a lot of gibberish! I asked “What do you use the terminal for?” And the developer responded, “I use it to navigate to different directories — folders”.

I said, “Why can’t you just click?”

“It’s faster.”

And I thought, how do you even know where you are going?

Recognizing the disbelief on my face, he said “It’s easier to install stuff. Like if I want something, I just go ‘sudo apt-get or pip install’.”

“But, how do you know — like — know what to type?”

And then he went on to show me how he googles a python package and instructions on the top say ‘pip install this.’ It still looked like a dark and complicated place that impressed me when I saw someone in it. I go, “Omg you’re a real hacker~~”

These days I can’t feel any more differently about the terminal. It feels like home. Like you’re finally in a quiet place and you can think in peace. How did it get from feeling scared to loving it? Stockholm’s syndrome, maybe. Or these few commands:

  • “cd <directory>” -> changes directory
  • “cd ..” -> goes up one directory
  • “ls” -> lists all the files and folders in the current directory
  • “cat <filename>” -> quickly view the contents of a single file
  • “nano <filename>” -> quick text editor

In addition to the above, I also regular use a few handy terminal commands like:

  • “find / -name <filename>” -> I use this when I don’t know where the file lives. I just want it to search the entire machine.

Meta Analysis

Many times, I’ll choose the command line interface over clicking in a GUI. I wondered why I felt that way. I think GUI’s are inherently designed to grab your attention. Certain buttons are more important than others so they’re bigger. GUI’s certainly don’t give you as much information as the terminal. The terminal, without a GUI, allows us to translate our thoughts directly. Like injecting medication through the vein rather than cooking the medication into food, chewing, and digesting it. Both methods are good for different purposes but the terminal is a place where one can do things with less distraction. That’s the key difference because sometimes, programming can be concentration/focus intensive.

Improve it with aliases

Even though the terminal is a beautifully simple place, sometimes it’s just NOT simple and direct enough. For example, I used cd .. a lot. Infact, sometimes I jump up multiple directory levels. So I created an alias that will save me some time:

alias ..="cd .."alias ...="cd ../.."alias ....="cd ../../.."

To create your own alias, go to your root directory. In your terminal, you can simple type in “cd” and you will be tossed into your root directory designated by a tilda (~) symbol. Now you can view all the files there with ls . The file we are going to edit is in here but you can’t see it with a simple ls , you need ls -a to view .bash_profile .

Is the file there? If not, do not worry. We will create one. Enter: nano .bash_profile It will open up the terminal text editor. If the files doesn’t exist, it will create one.

An alias is designated with the term “alias” in front of it. Then, enter the shortcut you’ll like to type. And then, enter the long form of the command separated with an equal (=) sign.

Now, when I type .. I will go up one directory. ... will go up two directories.

Alias for one directory

Let’s say I am working on this project and I know I will be constantly going to one directory. I’ll usually make an alias for it. alias code=’cd ~/Documents/code'

Alias for scripts

I can make an alias to run a script too! Let’s say there’s a project I want to spin up on the server. It can do that!

alias startgetmypup='cd ~/Documents/code/dog-shelter-app; python3 app.py';

I fit two long commands into one alias.

Aliases for Django

I work with the new Django which uses pipenv 2.0. The command is pretty long. Every command must start with pipenv run ./manage.py It gets pretty ridiculous in development because I have to type this over and over. A normal routine for me would be:

  1. pipenv run ./manage.py makemigrations
  2. pipenv run ./manage.py migrate
  3. pipenv run ./manage.py runserver

Now, it’s pmm, pm, pr. Or even faster, pmr.

alias pp='pipenv run ./manage.py';alias pmm='pp makemigrations';alias pm='pp migrate';alias pr='pp runserver';alias pmr='pp makemigrations; pp migrate; pp runserver';

If you are wondering why programmers put so much effort into jazzing up the terminal, I think we are trying to streamline all the distractions. I personally have a monkey mind. I struggle with staying focused (and off reddit). I personally don’t like spending a lot of time searching for a file or scanning directories to see if it is the right now. Those extra seconds add up. It’s a two edged blade because I lose traction when I spend too much just looking.

Colors!

You can also customize your terminal with colors! Stick this code right in the .bash_profile:

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "export CLICOLOR=1export LSCOLORS=Fxfxcxdxbxegedabagacadalias ls='ls -Fh'

Use this handy tool to pick and generate your own LSCOLORS codes.

Terminal Tools

This website saved my butt so many times. So, sometimes terminal commands aren’t clear. The terminal comes with a manual. You can type in man ls which will return the manual for the command ls. But the manual is terrible! Instead, I go ahead and google it. This is the BEST website for terminal commands: https://explainshell.com/

The terminal feels like home.

Software Engineer — Blockchain, Cybersecurity, and Commercial Space