Modify ZShell Defaults in macOS

Background

I'm finding myself using the Terminal quite a bit more in my job. I spent a few minutes over the past few days looking at different ways to make the default terminal layout in macOS better. While there are many plugins out there for doing this (Oh-My-Zsh), I wanted to do something a little more straightforward.

How You Change zsh Default Layouts

Armin Briegel has a great article about customizing the zsh prompt in his moving to zsh series. The basics come down to the following - make some changes to the file at ~/.zshrc and then enjoy the fruits of your labor! This file is also where you can add zsh functions (e.g. reusable pieces of code.)

My Current zsh Defaults

Here's the contents of my ~/.zshrc file:

 1PROMPT='%(?.%F{green}√.%F{red}?%?)%f %B%F{240}%1~%f%b %# '
 2
 3export PATH=$HOME/.gem/ruby/X.X.0/bin:$PATH
 4export GEM_HOME=$HOME/gems
 5export PATH=$HOME/gems/bin:$PATH
 6
 7movc () {
 8    ffmpeg -i $1 -c:v libx264 -preset fast "${1%.mov}"-opt.mov
 9    newname="${1%.mov}"-opt.mov
10    origsize=`du -k "$1" | cut -f1`
11    newsize=`du -k $newname | cut -f1`
12
13    echo  -e '\n'$1   $origsize"KB"
14    echo  $newname   $newsize"KB"
15}
16
17mp4c () {
18  ffmpeg -i $1 -c:v libx264 -preset fast "${1%.mp4}"-opt.mp4
19  newname="${1%.mp4}"-opt.mp4
20  origsize=`du -k "$1" | cut -f1`
21  newsize=`du -k $newname | cut -f1`
22
23  echo  -e '\n'$1   $origsize"KB"
24  echo  $newname   $newsize"KB"
25}
26
27mpgc () {
28    ffmpeg -i $1 -c:v libx264 -preset fast "${1%.mpg}"-opt.mpg
29    newname="${1%.mpg}"-opt.mpg
30    origsize=`du -k "$1" | cut -f1`
31    newsize=`du -k $newname | cut -f1`
32
33    echo  -e '\n'$1   $origsize"KB"
34    echo  $newname   $newsize"KB"
35}
36
37# Move 'up' so many directories instead of using several cd ../../, etc.
38up() { 
39    cd $(eval printf '../'%.0s {1..$1}) && pwd; 
40}

Breaking Down the Defaults

The first line (PROMPT='%(?.%F{green}√.%F{red}?%?)%f %B%F{240}%1~%f%b %# ') was pulled straight from Armin's Customizing the zsh prompt article. I love it because it's generally very minimal, but when you start diving into the filesystem it starts to give you an idea of where you're at. He's also embedded a return-code indicator, which is handy when running long commands.

The next three export lines are probably recognizable by anyone building Jekyll websites.

The next 3 sections of code are functions. In my job, I create a number of video files that get shared via Powerpoints and/or posted to YouTube. These 3 functions are shortcut command lines to use FFmpeg and drastically reduce the file size on video content. Basically, I can take an MP4 file output from Camtasia, and run mp4c video.mp4 to kick off an FFmpeg compression that outputs that same file (reduced in size) as video-opt.mp4. Credit to jprichards for the code for this one.

The last function I found on Reddit and find myself doing this exact thing constantly. It's going to be handy being able to simply type up 3 to change directories.