Back to Blog

Simplified Your Mundane Engineering Workflow with Aliases

5 min read min read
ProductivityDevOpsCLI

Introduction

As software engineers, we often find ourselves typing the same commands repeatedly. Whether it's navigating to a specific directory, running a series of git commands, or starting development servers, these repetitive tasks can add up to significant time loss.

The solution? Shell aliases! In this article, we'll explore how to use .bashrc (for Bash users) or .zshrc (for Zsh users) aliases to create powerful shortcuts that will streamline your workflow.

What are Shell Aliases?

Shell aliases are shortcuts that allow you to create custom commands. They're essentially abbreviations for longer commands or command sequences.

For example, instead of typing: ```bash cd ~/projects/my-awesome-project && npm run dev ```

You could simply type: ```bash myproject ```

Setting Up Aliases

For Bash Users

Edit your .bashrc file: ```bash nano ~/.bashrc ```

For Zsh Users

Edit your .zshrc file: ```bash nano ~/.zshrc ```

After making changes, reload your configuration: ```bash

For Bash

source ~/.bashrc

For Zsh

source ~/.zshrc ```

Essential Aliases for Developers

Navigation Shortcuts

```bash

Quick navigation

alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..'

Project directories

alias projects='cd ~/projects' alias work='cd ~/work' alias personal='cd ~/personal' ```

Git Aliases

```bash

Git shortcuts

alias gs='git status' alias ga='git add' alias gaa='git add .' alias gc='git commit -m' alias gp='git push' alias gpl='git pull' alias gco='git checkout' alias gb='git branch' alias glog='git log --oneline --graph --all'

Git commit with timestamp

alias gct='git commit -m "$(date +"%Y-%m-%d %H:%M:%S")"'

Quick push

alias push='git add . && git commit -m "quick update" && git push' ```

NPM/Yarn Shortcuts

```bash

Package manager aliases

alias ni='npm install' alias nid='npm install --save-dev' alias nr='npm run' alias ns='npm start' alias nt='npm test' alias nb='npm run build'

Yarn alternatives

alias yi='yarn install' alias ya='yarn add' alias yad='yarn add --dev' alias yr='yarn run' ```

Docker Aliases

```bash

Docker shortcuts

alias d='docker' alias dc='docker-compose' alias dps='docker ps' alias dpa='docker ps -a' alias di='docker images' alias dstop='docker stop $(docker ps -q)' alias drm='docker rm $(docker ps -a -q)' ```

System Aliases

```bash

Clear terminal

alias c='clear' alias cl='clear && ls'

List files

alias ll='ls -lah' alias la='ls -A'

Reload shell

alias reload='source ~/.zshrc' # or ~/.bashrc ```

Advanced Aliases with Functions

Sometimes you need more than a simple alias. Here are some function-based aliases:

```bash

Create and enter directory

mkcd() { mkdir -p "$1" && cd "$1" }

Find and kill process by port

killport() { lsof -ti:$1 | xargs kill -9 }

Git commit with custom message

gcm() { git commit -m "$*" }

Create React component

create-component() { mkdir -p "components/$1" touch "components/$1/index.tsx" touch "components/$1/$1.module.css" echo "Component $1 created" }

Quick server

serve() { python3 -m http.server ${1:-8000} }

Extract any archive

extract() { if [ -f $1 ]; then case $1 in *.tar.bz2) tar xjf $1 ;; *.tar.gz) tar xzf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar e $1 ;; *.gz) gunzip $1 ;; *.tar) tar xf $1 ;; *.tbz2) tar xjf $1 ;; *.tgz) tar xzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *.7z) 7z x $1 ;; *) echo "'$1' cannot be extracted" ;; esac else echo "'$1' is not a valid file" fi } ```

Project-Specific Aliases

Create aliases for your most-used projects:

```bash

Personal blog

alias blog='cd ~/projects/my-blog && code . && npm run dev'

Work project

alias work-api='cd ~/work/api-service && code . && docker-compose up'

Side project

alias side='cd ~/personal/side-project && npm run dev' ```

Conditional Aliases

Different aliases for different environments:

```bash

Different behavior based on OS

if [[ "$OSTYPE" == "darwin"* ]]; then

macOS

alias update='brew update && brew upgrade' elif [[ "$OSTYPE" == "linux-gnu"* ]]; then

Linux

alias update='sudo apt update && sudo apt upgrade' fi ```

Time-Saving Aliases

```bash

Current date and time

alias now='date +"%Y-%m-%d %H:%M:%S"'

Week number

alias week='date +%V'

IP address

alias myip='curl ipinfo.io/ip'

Speedtest

alias speedtest='curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python3 -'

Weather

alias weather='curl wttr.in' ```

Best Practices

  1. Keep it simple: Don't create aliases that are harder to remember than the original command
  2. Use meaningful names: Choose names that clearly indicate what the alias does
  3. Document your aliases: Add comments in your .bashrc/.zshrc
  4. Share with your team: Consider creating a shared aliases file for team projects
  5. Back up your configuration: Keep your shell config in a dotfiles repository

My Personal Aliases

Here's a snippet from my actual .zshrc:

```bash

Quick access

alias code='cd ~/code' alias dotfiles='cd ~/dotfiles && code .'

Git shortcuts

alias gst='git status' alias gco='git checkout' alias gcb='git checkout -b' alias wip='git add . && git commit -m "WIP" --no-verify'

Project launchers

alias api='cd ~/work/api && docker-compose up' alias frontend='cd ~/work/frontend && npm run dev'

Utils

alias reload='source ~/.zshrc && echo "Shell reloaded!"' alias aliases='cat ~/.zshrc | grep alias' ```

Conclusion

Shell aliases are a simple yet powerful way to boost your productivity. By creating shortcuts for your most common tasks, you can save hundreds of keystrokes every day and reduce the cognitive load of remembering complex commands.

Start small by creating aliases for your most frequent commands, and gradually build up your personal toolkit. Your future self will thank you!

What are your favorite aliases? Share them in the comments below! ```