Skip to main content

Drush alias FTW

If you are lazy and you do not want to type vendor/bin/drush every time you want to use drush cli, then this is a nice alias simple trick that i use for every new drupal installation (ubuntu linux).

First we need to create a .bash_aliases file (if this does not exist already) at ~/ .

This is where you will find the .bashrc file and inside somewhere at the end of this file we read

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

So we type:

touch ~/.bash_aliases

and then

vi ~/.bash_aliases

With the vi editor we type i (insert - edit mode)

and add this:

alias drush = 'vendor/bin/drush'

and then we reload the .bashrc file in order for our alias to work.

source ~/.bashrc

Now after this every time you are at /var/www/html or httpdocs/ or at the root of the drupal installation website you just need to type drush instead of vendor/bin/drush.

So this something that you can use for anything else. For example if you want to type cu instead of composer update or ga instead of git add or gpm instead of git push origin main etc.

 

p.s: this works for mac too just find the .bashrc file and follow the instructions you will find. The process is almost identical with the above example.

 

terminal