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. It solves a lot of the headaches associated with the default Terminal.app. Other popular choices are hyper and alacritty.
For my shell I use oh my zsh. The primary benefit of oh-my-zsh is the "plugins" written by other users (more on this later).
2: Love your theme and prompt
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.
Here's the code for the prompt I use:
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
plugins=(
git
copyfile
)
For oh-my-zsh, you should browse the list of 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
The git plugin gives you a ton of useful aliases and functions that cuts out a lot of characters from your git commands.
Autosuggestions
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 to be invaluable because it makes git diff
output so much easier to read.
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:
# in your .zshrc
alias gls="git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(refname:short)'"
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. 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.
Top comments (0)