loading...

Bash profile shortcuts and terminal customizations

kronicle114 profile image Trisha Aguinaldo ・3 min read

The type of work I do requires me to switch between git branches constantly. Over time, I've built a list of shortcuts and customizations that made my life easier.

Read along if you want to customize your terminal output and copy & paste some useful shortcuts for docker and git.

Jazz up your terminal

Add an emoji on your user name and show the relative path of your directory

Turn this:

trisha @ /codewars  $

Into this:

trisha🔥 @ ~/projects/codewars  $
  • Copy and Paste into your .bash_profile and re-open your shell:
export PS1="\u🔥 @ \w $ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad

PS1 will determine the display path. You can even add an emoji as seen above (🔥).
CLICOLOR will determine the output color theme
LSCOLORS determines the background.

Terminal profiles and window arrangements

Use a terminal emulator (like iTerm2) to quickly launch profile configurations. Useful if you have a couple of full-stack projects you're working on and want to launch the application using a single command.

CTRL + SHIFT + R will quickly open a saved window arrangement with whatever profiles you configure it with. It'll look something like this:

iterm2 window arrangement

^ Notice those tabs, eh?? What’s so cool about it is that you can save full-stack repos in a window arrangement once and then switch tabs without needing to change directories constantly. What a time saver! :D

Pro-tip: You can also add a starting script on your saved profile. I typically add cd <file_path>; git fetch; git status; so when I open the profile, it’s already in the correct directory and it tells me the status of my current branch.

iTerm2 link https://iterm2.com/index.html

Terminal color schemes

If you want your bash outputs to look better, try out iTerm2's themes. It makes a difference when you are reading the logs and error stacks.

example of dracula theme iterm2

You'll want to download the .txt file of your color scheme and then upload it on your iterm2 preferences < profiles < colors < color schemes:

iterm2 preferences

Shortcuts / Aliases

Here's a list of useful git and docker aliases that I use daily. It's super helpful especially when your repos have submodules that you need to update daily.

# ----------------------
# Git Aliases
# ----------------------
alias upstream='git push --set-upstream origin'
alias ga='git add -A'
alias gb='git branch'
alias gbd='git branch --D '
alias gcm='git commit --message'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcod='git checkout development'
alias gd='git diff'
alias glg='git log --graph --oneline --decorate --all'
alias gp='git pull'
alias gs='git status'
alias gf='git fetch'
alias grh='git reset --hard' 



# ----------------------
# Git Submodule ForEach Aliases
# ----------------------
alias gsf='git submodule foreach'
alias gcos='git submodule foreach git checkout'
alias gcods='git submodule foreach git checkout development'
alias gfs='git submodule foreach git fetch'
alias gss='git submodule foreach git status'
alias gbs='git submodule foreach git branch' 
alias gps='git submodule foreach git pull'
alias grhs='git submodule foreach git reset --hard' 



# ----------------------
# Docker Aliases
# ----------------------
alias dc='docker-compose'
alias dcb='docker-compose up --build' 
alias dps='docker ps -a'
alias drm='docker container rm' 

Posted on by:

Discussion

markdown guide
 
 
 

We share a lot of the same aliases! I kept gp'ing when I meant to push, so I've changed them to gph and gpl and am making heavy use of positional parameters with most others. Thanks for the share!

 

I definitely didn’t want a shortcut for git push. Especially when I have access to push to the master branch at work. Imagine? 😂 But I love how customizable shortcuts are. Beats having to type out the entire word when you’re short for time.

 

I am very happy I stumbled upon your post....iterm2 just changed my life. :) Thank you!

 

I’m so glad that helped you!! Happy coding :)

 

How do you, 🔥Trisha, edit your bash profile? I edit ~/.baschrc then source .bashrc but im curious if there is a better or easier way.

 

Hi Edwrd T! After creating my .bash_profile, I usually just use vim to update it (vim .bash_profile). I think vim is the quickest way to edit single files. But here are other ways to edit the file in a mac os:

  1. Open a terminal shell
  2. Change directory to your home folder. cd ~/
  3. Enter the command touch .bash_profile to create a new file.
  4. Edit .bash_profile on your IDE (open .bash_profile) or enter open -e .bash_profile to open it in TextEdit.