My Terminal Aliases as a Laravel/Pest Developer

Updated:

First, let's just start by clarifying the basics.

What Is A Terminal Alias?

It's a funky name for a shortcut. It's no more, than just a shortcut for a terminal command.

Here's a real world example for a termianl alias:

Say, you're a Laravel developer and you find yourself typing php artisan ... a lot.

What I've done instead is add this to my .bash_profile:

alias pa="php artisan"

So now all I type is pa.

Here are a few examples:

  • pa migrate
  • pa migrate:rollback
  • pa make:model Post

Setting Up Terminal Aliases

You can do this many ways, but I'm going to talk about the way I've done it to work with my public dotfiles

I run ohmyzsh locally, so in my .zsh file I have the following:

source ~/.bash_profile
source ~/.functions
source ~/.aliases

I use two files: .bash_profile and .aliases for quite a simple reason:

.bash_profile is actually commited to my dotfiles repository so I have a second file .aliases for any personal and private aliases that I don't want to share to github.

So when wanting to create a terminal aliases, make sure you have source ./bash_profile in your .zsh file if you're using it, or else it's typically included by default.

Terminal aliases can be set up with the following format:

alias <name>="<command>"

Note: Everytime you save or update your .bash_profile you will need to restart your entire terminal, or just run source ./bash_profile.

My Aliases

I'll try to group these logically, but if you view my .bash_profile above on github, you'll see they're kind of all over the place.

General

alias code='cd ~/Code' # navigates to my code directory
alias dotfiles='cd ~/Code/dotfiles' # navigates to the dotfiles directory if I need to make any changes
alias q="cd ~ && clear" # resets my terminal

Developer

alias p="./vendor/bin/pest" # runs pest
alias pc="p --type-coverage" # runs a coverage check fro pest
alias stan="vendor/bin/phpstan analyse --memory-limit=2G" # runs phpstan
 
alias cdump="composer dumpautoload" # a sneaky composer dumpautoload alias, as typing that is too long

Laravel

alias pa="php artisan" # shortcut for php artisan
alias dbfresh="pa migrate:fresh --seed" # wipes and re-seeds the database
alias op="php artisan optimize" # shortcut to run optimise
alias mfs="dbfresh" # another way to wipe and re-seed the database
alias mr="php artisan migrate:rollback" # rollback the last database migration

Frontend

alias twatch="TAILWIND_MODE=watch npx mix watch" # I don't know why I have this, or what it does, but I run twatch every day

Git

I have a fair few git aliases, so I'll try to highlight what I actually use

alias repush='git pull --rebase && git push'

I use this command quite a fair bit when working in teams, a great example is when you have a commit to push up, but there is also a commit to pull down, so you can just run repush and git will do the rebase without doing a merge commit. You may need to still do a merge commit if you have conflicts though.

alias gitclean="git checkout master && git fetch -p && git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -D"

This is a sneaky command to clean up any branches locally that once existed, but don't anymore. E.g: branches merged into other branches and then deleted.

alias publish='git push --set-upstream origin $(git branch | grep \* | cut -d " " -f2)'

This was a command that I used quite a bit previously, when pushing a newly created branch locally to the remote, but now you can simple set git config to do this automatically:

git config --global push.autoSetupRemote true
alias gl='git log --pretty=format:"%C(yellow)%h %ad%Cred%d %Creset%s%Cblue [%cn]" --decorate --date=short'

This prints git log to your terminal in a very easy to understand way:

alias gcp='git checkout -' # checkout previous branch
alias gmp='git merge -' # merge previous branch
alias mpb='gcp && git pull && gcp && gmp && git push' # swap to previous branch, pull, swab back to current branch, merge, and push

I use those 3 commands daily to handle swapping branches, merging, etc. Very useful.

alias gd='git diff'

A small aliases for git diff, which prints the changes you have locally compared to your remote branch.

Misc

alias shrug="echo '¯\_(ツ)_/¯' | pbcopy" # if I need to shrug someone
 
alias update='sudo softwareupdate -i -a; brew update; brew upgrade; brew cleanup; npm install npm -g; npm update -g; sudo gem update --system; sudo gem update; sudo gem cleanup' # update everything
 
# navigation shortcuts
alias home='clear && cd ~ && ls'
alias downloads='clear && cd ~/Downloads && ls'
alias desktop='clear && cd ~/Desktop && ls'

Thoughts

One thing I've been wanting to set up quite recently is z to help navigate through files easier, but I've honestly found myself just creating some aliases in my .aliases file:

alias cl="cd ~/Code/careerlane"

Other Terminal Aliases

@dcblogdev published a blog post not too long ago on his terminal aliases - I definitely recommend checking it out.

We do share some of the same aliases, but if you combine both of ours, you'll get over 10+ years worth of aliases that are used every day.