Let’s Shorten those Shell Commands

3 min read, posted on Feb 14, 2020

Some useful shell aliases for your development pleasure.

#bash #dev #zsh #tips

Photo by <a href="https://unsplash.com/@hellomm" target="_blank">xiaokang Zhang</a> on <a href="https://unsplash.com" target="_blank">Unsplash</a>

Photo by xiaokang Zhang on Unsplash

Much like moving from Windows to a Mac, using Bash/​ZSH shortcuts is something you start and don’t change your mind on. Well, that’s at least my case.

To setup yours, all you need to do is define them in your shell config (be it Bash or ZSH). I use ZSH with a sourced aliases file (containing aliases to edit both of these).

To start, create a new aliases file (touch ~/.aliases) and then open up ~/.bash_profile or ~/.bashrc if you’re using Bash, ~/.zshrc if it’s ZSH, and add the following anywhere in the file:

source ~/.aliases

Next, open up the aliases file and add each alias. Here are some I’ve gathered over the last two years. Admittedly, I don’t use them all, and sometimes forget half of them exist, but they’re useful to have nonetheless.


alias ..="cd .."
alias sshconfig="vi ~/.ssh/config"
alias copyssh="pbcopy < ~/.ssh/id_ed25519.pub" # pbcopy is mac-only
alias showssh="cat ~/.ssh/id_ed25519.pub"
alias publicip="curl icanhazip.com"


alias gs="git status"
alias gss="git status -s"
alias gc="git commit -m"
alias gb="git branch"
alias gco="git checkout"
alias gpl="git pull"
alias ga="git add ."
alias gd="git diff"
alias gds="git diff --stat"
alias gps="git push"
alias nah='git reset --hard;git clean -df'


alias ni="npm i"
alias nu="npm uninstall"
alias nrw="npm run watch"
alias nrh="npm run hot"
alias nrd="npm run dev"
alias nrs="npm run serve"
alias nrso="npm run serve -- --open"
alias nrp="npm run production"
alias nrb="npm run build"
alias nvp="npm version patch"
alias npp="npm publish"


alias art="php artisan"
alias migrate="art migrate --seed"
alias fresh="art migrate:fresh --seed"
alias rollback="art migrate:rollback"
alias routes="art route:list"
alias seed="art db:seed"
alias copyenv="cp .env.example .env"
alias artkey="art key:generate"
alias clearcache="art cache:clear"
alias ds="art dump-server"
alias tinker="art tinker"


alias ci="composer install"
alias cu="composer update"
alias cr="composer require"
alias cda="composer dumpautoload"


mcd() {
  # make a new directory (nested) and cd into it
  mkdir -p -- "$1" && cd -- "$1"

commit() {
  # git add and git commit
  ga && gc "$1"

push() {
  # git add, git commit, and git push
  commit "$1" && gps

take() {
  # take a new branch and push it to origin
  gco -b $1 && gps -u origin $1

editme() {
  # edit and source the ZSH profile
  vi ~/.zshrc
  source ~/.zshrc
  echo "$(tput setaf 2).zshrc sourced$(tput sgr0)"

editaliases() {
  # edit and source this file
  vi ~/.aliases
  source ~/.aliases
  echo "$(tput setaf 2).aliases sourced$(tput sgr0)"

tailthelog() {
  # tail the laravel log, trimming out the stack trace and adding some color
  tail -f -n 450 storage/logs/laravel*.log | grep -i -E "^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:" --color

simcontainer() {
  # xcun is mac-specific
  # open up the data directory for the current xcode simulator container
  open `xcrun simctl get_app_container booted $1 data` -a Finder

simdb() {
  # open up an app's sqlite db in TablePlus (change where needed)
  open `xcrun simctl get_app_container booted $1 data`/Documents/database.sqlite -a TablePlus

adbconnect() {
  # automatically add a USB-connected device to WiFi for app debugging without messy cables
  adb disconnect
  adb tcpip 5555
  sleep 3
  IP=$(adb shell ip addr show wlan0  | grep 'inet ' | cut -d' ' -f6| cut -d/ -f1)
  echo "${IP}"
  adb connect $IP

© Mike Rockétt.