Bash profile shortcuts and terminal customizations
Tags: bash, git, docker, submodules
Published: 2019-12-23 23:43:08

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: 
```bash
trisha @ /codewars  $
```

Into this:
```bash
trisha🔥 @ ~/projects/codewars  $
```

- Copy and Paste into your .bash_profile and re-open your shell:
```bash
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. 

- Read more here: http://osxdaily.com/2013/02/05/improve-terminal-appearance-mac-os-x/

### 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](https://drive.google.com/uc?id=1sYJjorBBt25w37QsxFRgmwbDpd41zZmi)

^ 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.

- Color Schemes https://github.com/mbadolato/iTerm2-Color-Schemes
- My fav (dracula): https://github.com/mbadolato/iTerm2-Color-Schemes/blob/master/schemes/Dracula.itermcolors

![example of dracula theme iterm2](https://drive.google.com/uc?id=10guCpxPArQXcMfpBqjDYfHJmY94b_J70)

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](https://drive.google.com/uc?id=1WUdYUFxBP7p1UOU_5IMHVXDLr1p_w0GD)


## 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.


```bash
# ----------------------
# 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' 
```