Do I look like a programmer now?
Today I spent a significant portion of my day learning about the command line and how useful it is. For those of you that are beginners like me and are here to join me in my journey of learning how to program from square one, the command line allows you navigate through your computer without the mouse. You can move files from one folder to the other, create new files and delete them, sort input alphabetically, output the number of lines, words, and characters in a file, and so much more. You can access the command line by typing in “terminal” into the Finder on a Mac *magic* there it is. The deepest, darkest secrets of your computer are now at your fingertips.
The most impressive discovery I made was the hidden .bash_profile. This is a file that will allow you to customize your terminal. I’m sure it has greater functionality than adding emojis to your terminal, but I got caught up in spicing up the looks of my terminal before I could explore the other possibilities. Take a look at the transformation:
More useful than the emoji was setting the command prompt to show my working directory. Let’s break down this one line:
export: makes the variable available to all the following sessions
PS1: sets the command prompt variable
\W: name of the current working directory
\h: host name
$: I wanted to keep that symbol, I could have very well changed it to @(0_0)@ if I wanted to.
This is what my command prompt looks like when my PS1 is set in the .bash_profile
In addition to changing my command prompt, I wanted to figure out what kinds of shortcuts (also called “aliases”) would help make my programming life a little easier. I was already tired of typing all the dots and dashes that go with moving up directories (cd ../../) so I decided to simplify that process in order to minimize mistakes and to save time. I also shortened up “clear” and “pwd” because I use those often and will save time by typing only one letter rather than typing out the whole word. Here’s what my ~/.bash_profile looks like now.
I researched more shortcuts but have found that at such an early stage of programming, it makes sense to build up my own customizations and libraries as I find the need for them. Copying preferences that other people have saved isn’t very useful for me because I often don’t know what the shortcuts are used for and it takes a lot of time just to memorize the aliases they chose.
If you are curious about your ~/.bash_profile, here are some beginner steps to playing around with it:
- Open your terminal.
- Type : nano ~/.bash_profile (It will open up a text editor and you are going to have to use you up and down arrows to navigate the .bash_profile.)
- add an alias : alias ..=“cd ..” (Now when you type .. in your terminal, it will automatically move up one directory.)
- Control + O ( to save)
- Press Enter
- Control + X ( to exit)
- source ~/.bash_profile ( type that in to activate the changes you made in your ~/.bash_profile)