On Oh My Zsh + iTerm workflows

On Oh My Zsh + iTerm workflows

Tags
Coding
Published
February 11, 2021

Oh My Zsh

Powerful combo of Zsh + a bunch of useful plugins

Custom Aliases

alias y="yarn"
alias ys="yarn start"
alias yt="yarn test"
alias gcm="git checkout master"

Useful default aliases

l # alias for ls -alh
g # alias for git
gco # alias for git checkout
gss # alias for git status -s
gcb # alias for git checkout -b
glog # alias for git log --oneline --decorate --graph

Full cheat sheet: https://github.com/ohmyzsh/ohmyzsh/wiki/Cheatsheet or use the alias command to see all available aliases

Use gcm + gco when rebasing

gcm # checkout master
g pull # pull the latest master
gco - # switch back to your working branch 
g rebase master
g push -f

Use shortcuts

- # shortcut for cd - : go to previous directory
~ # shortcut for cd ~ : go home
sudo !! # reruns previous command with sudo prefix. can also be done using `the eff`

Autojump

Very useful plugin, not Zsh specific. Let's you jump to any directory that you've already visited using fuzzy matching. E.g.

j 2020 # jumps to ~/Projects/www-wrapped-2020
j mob # jumps to ~/Projects/client-web/open/mobile-web-player

The F****

The Eff, as I will call it in the interest of keep it PG, is a self described tool that "corrects errors in previous console commands". It's kind of like a command line linter

I change the alias from, literally, fuck to sure.

brew install thefuck
echo 'eval $(thefuck --alias sure)' >> ~/.zshrc

Example usage

➜ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master


➜ sure
git push --set-upstream origin master [enter/↑/↓/ctrl+c]
Counting objects: 9, done.

Reverse search through command history

Not Zsh specific. Use ctrl + R

Alertnative to

  • Pressing up 1 million times
  • history | grep foo this is is a good option if you want to use regexs to search through mor e rows

iTerm2

cmd + d # create a new vertical session
shift + cmd + d # create a new horizontal session
cmd + t # create a new tab session

Settings

Enable option/alt + left || right moves the cursor across words

In Profiles > Keys, add the following

image
image

Enable "Reuse previous session's directory"

In Profiles > General > Working Directory, check "Reuse previous session's directory"

This means that whenever you start a new session using cmd + D, it puts you in the pwd of the last session

image

Workflow

I'll usually have one tab per "project/initiative", with one to four split session per tab, depending on the number of repos involved, e.g.

  • ys in the upper left
  • yt --watch in the lower left
  • zsh shell on the whole right half

Alertnative

Use tmux, which should actually work in conjunction with iTerm2.

VS Code

Follow the docs on launching from the command line. TLDR: cmd + P → seach for "install" → select "Shell Command: Install 'code' command in PATH"

image

This lets you open projects by doing

code .