5 Tips to Supercharge Your Terminal
Tags: tutorial, bash, beginners, productivity
Published: 2020-07-12 16:28:15

Sometimes using the terminal can be a nightmare. I've compiled a few tips that can help make the terminal less scary and more enjoyable.

# 1: Use the Right Tools

Two tools are essential for improving your terminal: your *app* and your *shell*.

For my app I use [iTerm2](https://www.iterm2.com/). It solves a lot of the headaches associated with the default Terminal.app. Other popular choices are [hyper](https://hyper.is/) and [alacritty](https://github.com/alacritty/alacritty).

For my shell I use [oh my zsh](https://ohmyz.sh/). The primary benefit of oh-my-zsh is the "plugins" written by other users (more on this later).

# 2: Love your theme and prompt

![Example terminal theme](https://dev-to-uploads.s3.amazonaws.com/i/6wxwqt37w15i2wiflmad.png)

You should find a theme and prompt that (1) you enjoy using and (2) presents useful information at a glance.

I enjoy dark mode with bright, easy to read colors. You can see I have a few useful snippets of information in my prompt: 
- The arrow at the beginning tells me if the previous command was successful (green) or failed (red) 
- The directory I'm currently in (with my `$HOME` represented as `~`)
- The branch I'm currently on 
- A yellow `x` if my branch is in a "dirty state"

You can browse available oh-my-zsh themes [here](https://github.com/ohmyzsh/ohmyzsh/wiki/Themes).

Here's the code for the prompt I use: 
```sh
function get_pwd() {
  echo "${PWD/$HOME/~}"
}

local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT='${ret_status}%{$fg[cyan]%} $(get_pwd)%{$reset_color%}$(git_prompt_info) '

ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%} (%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
```


# 3: Install the right plugins 
```sh
plugins=(
  git
  copyfile
)
```

For oh-my-zsh, you should browse the [list of awesome zsh plugins](https://github.com/unixorn/awesome-zsh-plugins). Installing these plugins is easy: you can make a list of them in your `.zshrc`, open a new terminal window, and they'll magically work. Here's a few of my favorites.

#### Git

![Terminal showing example of shortended git commands](https://dev-to-uploads.s3.amazonaws.com/i/dmkaoeh11xeuwdoiywtl.png)
The [git plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git) gives you a ton of useful aliases and functions that cuts out a lot of characters from your git commands.

#### Autosuggestions

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mto6gg2gklo25qu8kcy6.png)

Super useful tool that gives you autocomplete without having to comb through history.

#### Diff-so-fancy

This one isn't an oh-my-zsh plugin, but I've found [diff-so-fancy](https://github.com/so-fancy/diff-so-fancy) to be invaluable because it makes `git diff` output so much easier to read.

![Alt Text](https://user-images.githubusercontent.com/3429760/32387617-44c873da-c082-11e7-829c-6160b853adcb.png)

# 4: Alias your common operations

When you come across a long command that you struggle to remember, create an alias for it! 

For example, I enjoy having a command `gls` that acts like `ls`, but for my git branches, listing them in priority of most recently used. Here's how I defined that alias and an example usage:

```sh
# in your .zshrc
alias gls="git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(refname:short)'"
```

![Terminal image showing 5 most recent branches](https://dev-to-uploads.s3.amazonaws.com/i/ubtqwlzdpib07c9qulxm.png)

# 5: Create a git repo for your dotfiles

Inevitably, when you're exploring new terminal setups, you'll break something and want to revert to a previous state. Or you'll get a new computer, switch jobs, etc and struggle to get your previous setup working again.

A former (very talented) coworker of mine introduced to me to [the dotfile setup I use now](https://github.com/kc-beard/dotfiles). It's helped me undo some terrible errors, and makes it painless to switch to new computer.

--- 

Thanks for reading! Let me know your favorite terminal tips in the comments.