# Terminal Setup

A lot of people at work have been asking me how I set up my terminal, so I wrote this up to send to them. Hope you enjoy!

# Install ZSH

The shell I use is zsh. To install it, follow these instructions

# Install oh-my-zsh

oh-my-zsh is a plugin/theming library thingie for zsh.

Make sure to take a look at the plugins and enable any that might be useful for you. I’m a big fan of colored-man-pages. Man pages become way easier to read when they have different colors, not just black and white.

# Install Powerline Fonts

All of the fancy oh-my-zsh themes use the powerline fonts.

Depending on your terminal, you may need to change the default font to one of the Powerline fonts in order to get it to appear correctly. I currently use Menlo Regular, but honestly that’s just one I picked at random and stuck with. I don’t know if there’s a better one out there.

oh-my-zsh has a bunch to choose from, but if you choose anything other than agnoster, I can’t help you. Edit your ~/.zshrc file and set ZSH_THEME=agnoster. You’ll thank me later.

One of the reasons I really like agnoster is that the terminal prompt is incredibly good looking, but also very easy to extend. Props to the writer, because these are some of the cleanest shell scripts I’ve ever seen.

To start customizing your theme, copy ~/.oh-my-zsh/themes/agnoster.zsh-theme to ~/.oh-my-zsh/custom/themes/agnoster.zsh-theme. After this, you can edit the theme as you see fit. The build_prompt() function is the main one that calls all the others. Here’s what mine currently looks like:

## Main prompt
build_prompt() {
RETVAL=$? prompt_status prompt_virtualenv # prompt_context prompt_dir prompt_git # prompt_bzr # prompt_hg prompt_aws_env prompt_k8s_context prompt_end }  All it does is set an environment variable, and then calls a bunch of functions to construct the different parts of the prompt. Or you can just comment out parts that you won’t use. prompt_status displays the status of the previous command, along with some other things that I can never remember. prompt_virtualenv displays the name of the currently configured virtualenv. Useful if you do a lot of python development. prompt_git is fantastic if you use git. It displays the branch name and lets you know if you’re up to date with your remote branch, among other things. prompt_aws_env and prompt_k8s_context are ones that I added. prompt_aws_env is only really relevant to my work so I won’t bother explaining that. But if you work with Kubernetes at all, I highly recommend you add the prompt_k8s_context function. The code is below: prompt_k8s_context() { local kube_context=$(kubectl config current-context)
local kube_ns=$(kubectl config view --minify -o jsonpath='{.contexts[0].context.namespace}') prompt_segment blue black "❂${kube_context}:\${kube_ns}"
}


That’s it?

Hell yeah that’s it. The prompt_segment helper function that the agnoster author made is SUPER USEFUL.

Hope this was helpful! Let me know of anything that needs clarified/is no longer up to date.

Latest Posts