Andrei Dobrinski's Blog

Helpful Bash/Zsh Aliases

This is a list of aliases that I use in the terminal that help me be more productive by automating parts of my workflow. Hopefully they can help you as well!

I work on machine running macOS, zsh, and the stock Terminal app.

Add a new alias

alias addalias="code ~/.zshrc"

Opens VS Code with my current zsh aliases.

Open an environment to learn from a course

alias learn="cd path/to/repo && code . & open -a 'Google Chrome' https://link-to-current-course.com"

This opens VS Code with the repo and Chrome with the course material. I’ll update the repo path and course link as they change.

My next step is to snap Chrome to the left half and VS Code to the right half of the screen. If you have any suggestions, let me know!

Open and run a project

alias pfl="cd path/to/portfolio && code . && yarn start"

I use a few of these for projects I frequently come back to. I alias pfl (as in “portfolio”) to navigate into the repo, open VS Code and run a project. I use this less frequently because of the VS Code Workspace Switcher extension, but it’s still handy.

Open multiple browsers to localhost

alias cbt="open -a 'Google Chrome' http://localhost:3000 & open -a 'Firefox Developer Edition' http://localhost:3000 & open -a 'Safari' http://localhost:3000"

cbt (cross-browser test) opens localhost:3000 in Chrome, Firefox and Safari. This could further be improved by passing the localhost port as an argument.

Open files with changes from a branch in VS Code

wip() {
  git diff --name-only $1 | xargs code
}

# shortcut with main branch
alias wipm="git diff --name-only main | xargs code"

wip (work in progress) accepts and argument of a branch name, performs a git diff of changed files with the current branch and pipes the result into VS Code, which opens each file. I find this useful for context switching, as it quickly takes my workspace back into the state it was when I was last working on a branch. It also allows me to clean up my workspace knowing that I can easily return to the work-in-progress state.

Run an Android simulator

alias runavd="~/Library/Android/sdk/emulator/emulator -avd Nexus_5X_API_28"

I use this for Flutter and React Native development as it lets me quickly open the emulator without having to open and navigate through Android Studio. The path and avd should both be valid to use.

Open a Jira ticket in the browser

jira() {
  open -a 'Google Chrome' https://your-company.atlassian.net/browse/BOARD-$1
}

I pass ticket number as an argument and Chrome opens with that ticket. Useful for when a teammate gives me a ticket number verbally.

Push current git branch to staging

alias gps='git push staging $(git rev-parse --abbrev-ref HEAD):main -f'

The prerequisite here is that my environment needs to be configured so that git push staging your-branch:main -f is the command to push to staging. The other piece in the gps (git push staging) alias finds the git branch that I’m currently on, so that I don’t need to write out the entire command.

alias grb="git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format='%(refname:short)'"

grb (git recent branches) gives me the 10 most recent branches in my git repository.

testDiff() {
  newTests=$(git diff --name-only main | grep .test.'[ts|tsx|js|jsx]')
  array=()
  for FILE in $(echo "${newTests[@]}");do
    array+=("${FILE}")
  done
  testOutput=$(npm run test -- --findRelatedTests $array --verbose)
  echo $testOutput
}

Keep in mind that this function is hardcoded to diff against the main branch.

Decrease Key Repeat and Increase Track Speed on Mac

Decreasing key repeats helps by allowing for more inputs on the press-and-hold of a key. InitialKeyRepeat is the throttle time in ms between the input on the key press and the second input on the press-and-hold. KeyRepeat is the throttle time in ms between inputs after the InitialKeyRepeat, repeating for as long as the key is held down. Keep in mind that a system restart is needed for these changes to take effect.

# decrease key repeats
defaults write -g KeyRepeat -int 1
defaults read -g KeyRepeat
# returns 1

defaults write -g InitialKeyRepeat -int 10
defaults read -g InitialKeyRepeat
# returns 10

# increase tracking speed
defaults write -g com.apple.trackpad.scaling -float 3.0
defaults read -g com.apple.trackpad.scaling
# returns 3

defaults write -g com.apple.mouse.scaling -float 10.0
defaults read -g com.apple.mouse.scaling
# returns 10

Miscellaneous git shortcuts

alias gco="git checkout"
alias branch="git checkout -b"
alias gcm="git checkout main"
alias gc-="git checkout -"

The goal with these is to save a few keystrokes on commands I frequently use.

If you have have any suggestions for improvements or feedback, I’d love to hear it! Let me know via Twitter.

Edit on GitHub

Back to All Posts
Built with ❤️  in 🇨🇦