DEV Community

Cover image for Improving your workflow with aliases! πŸš€πŸš€πŸš€
Kyle Hunter
Kyle Hunter

Posted on

Improving your workflow with aliases! πŸš€πŸš€πŸš€

Improving your workflow with aliases! πŸš€

πŸ€” But what are aliases?

Aliases are a great way to shave off time spent when jumping around the file system via the terminal or working with git. At their core, aliases are custom strings/names (usually short in length) that are set to one or more commands (usually longer in length). You define these custom alias names in a .bash_alias file (more on this later) and then can enter them in the terminal.

You can get really creative when defining aliases to help cut down the amount of time you spend typing long chained commands out. This might seem like a minor improvement but it adds up over time!

🀯 Aliases sound awesome... how can I get started?

I use macOS so that will be the environment I center my steps around. Here are initial steps to get started:

  1. Open Terminal.
  2. In Terminal, navigate to your users root directory and create a new .bash_profile file by:
cd ~
touch .bash_profile
Enter fullscreen mode Exit fullscreen mode

You now have the ability to add custom aliases (each on a new line) in the .bash_profile file. Be sure to restart your Terminal application after any updates made to this file. Also, if you're looking for the file in Finder, you need to show all hidden files (hit shift+command+. while in Finder).

πŸ’» What are some useful aliases I can get started with?

Navigating Folders

workspace='/Users/your username/workspace/'
alias home='cd $workspace; pwd;'
alias documents='cd $workspace; cd ../Documents/'
alias external='cd $workspace; cd /Volumes/name of external drive'
alias myrepo='cd $workspace; cd myrepo'
alias vs='code .'

Git Shortcuts

alias gf='git fetch --all -p'
alias gpom='git pull origin master'
alias gb='git branch'
alias gl='git gl'
alias grh='git reset --hard'
alias gsl='git stash list'
alias gspop='git stash pop'

❓Alright, I'm convinced and ready to create some aliases for my Terminal workflow... but are there any negatives of using aliases?

This all sounds great and aliases are very convenient, but of course there is a potential negative with aliases and that is you may rely on them and forget what the original commands are. It's helpful to only use aliases on one of your computers if you have the luxury of multiple computers. If not, I personally recommend mixing in the actual commands from time to time so you don't end up in a bind if you need to work on a different machine!

Drop a comment below with any useful aliases that you can think of incorporating into your workflow! πŸ˜ƒ

Top comments (2)

Collapse
 
patricnox profile image
PatricNox

Here's my bash_profile, been using it for around 2 years now. :)

gist.github.com/PatricNox/83f714e9...

source ~/.profile
export PATH=$PATH:/Users/lia/.npm-packages/bin

## General shorthands.
alias update='source ~/.bashrc'
alias sshkey="cat ~/.ssh/id_rsa.pub | pbcopy"
alias httpdconf="code /usr/local/etc/httpd/httpd.conf"

## Local.
alias startlocal="sudo apachectl start && brew services start mysql"
alias stoplocal="sudo apachectl stop && brew services stop mysql"
alias mysql=/usr/local/bin/mysql
alias mysqladmin=/usr/local/bin/mysqladmin

## Custom tools.
alias dbsearch="cd ~/playground/search && php -S localhost:1337 -t . ; cd -"
alias localtest="cd ~/playground/localtest && code . ; php -S localhost:9090 -t . ; cd -"

## Docker shorthands.
alias dc="docker-compose"
alias d="./dev.sh"
alias dd="../dev.sh"
alias dsup="docker-compose up -d"
alias dsall='docker stop $(docker ps -aq) && docker rm $(docker ps -aq)'
alias dsr="dsall && dsup"

## Git shorthands.
alias gp="git pull"
alias wip="git reset --soft head~"

## Vagrant.
alias vup="vagrant up && vagrant ssh"

## Composer Laravel - Cache clear and stuff
alias composercc="composer dump-autoload -o && dd artisan cache:clear && composer clear-cache && dsr"

## Shorthand for ./dev.sh drush for multi-docker
md() {
  d drush $1 $2 $3 $4
}

# Add entry to hosts file, needed for Multidocker.
mdaddhost() {
  sudo echo "127.0.0.1 $1.dev.local" | sudo tee -a /etc/hosts
}

# Drush in multi-docker
function mush() {
    dir=${PWD##*/}
    echo
    echo '_____________'
    echo 'Project:' ${dir}
    echo '_____________'
    echo 

    (cd ~/docks/multi-docker ; ./dev.sh drush ${dir} "$@")
}

## Git shortcuts.
# git push
gpp() { 
  git push -u origin "$1" 
}

# git checkout
gc() { 
  git checkout "$1" 
}

## Misc. 
# ruby, sbin, openssl.
export PATH="/usr/local/opt/ruby/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"
export PATH="/usr/local/opt/openssl/bin:$PATH"

# Autocomplete Git.
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
if [ -f ~/.git-completion.bash ]; then
  . ~/.git-completion.bash
fi

# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# gem
export GEM_HOME="/usr/local/lib/ruby/gems/2.6.0"
export PATH="$GEM_HOME/bin:$PATH"

# Fixes problem with "perl: warning: Setting locale failed.".
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

# Other 
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"
Collapse
 
kylehunter profile image
Kyle Hunter

Thanks for sharing πŸ˜„ you gave me a few ideas of new ones I can mix in to my workflow!