4 Ways I Effectively Use The Mac Terminal

Here are four terminal tips I wish I knew when I first started programming.
Displaying the name of the git branch I am working on
Displaying the name of the git branch I have checked out helps me keep track what I am working on as well as prevents me from committing to an unintended branch. l no longer have to run the git branch
command to see what branch I have checked out.
Instructions to add this to your terminal:
- If you don’t already have a
.bash_profile
make one:touch ~/.bash_profile
. This adds a.bash_profile
file to your home directory. - Open this file using any editor and add the following code:
3. Finally, make sure to source ~/.bash_profile
or open a new terminal window to see the effects.
Repositioning my cursor
If you use the left and right arrow keys to navigate your terminal command, I have great news for you. There is a way to move the cursor without using the arrow keys. The solution is to simply press the option
key while simultaneously moving your mouse and clicking where you would like to move the cursor.
Splitting my terminal window
command + d
Often when programming, I like to preserve the window I am working in and open a new window to test a theory or just check something out. In this case I’ll split my pane using the shortcut command + d.
Opening finder
open .
By using the command open .
(notice the trailing dot), I am able to open the working directory in finder. Although, I usually navigate files and folders using the terminal I sometimes find it useful to see a visual of the file structure as it helps provide more context.
Resources
Display branch name on Terminal Prompt: https://www.mfitzp.com/article/add-git-branch-name-to-terminal-prompt-mac/
More terminal shortcuts can be found here: https://support.apple.com/guide/terminal/keyboard-shortcuts-trmlshtcts/mac