Optimizing the terminal for Drush

The drush-cli command adds a few environment settings to our terminal session so we can issue Drush commands even faster. Among other things, it adds the following features after being executed:

  • Execute all Drush commands against a specific site.
  • Change directory to the root, modules, or files directories of a site.
  • List files within a directory of a site.
  • Execute commands without having to type drush at the start.

We will first enter on the Drush CLI and test a few commands. Then we will explain how to add Drush CLI configuration to our default terminal profile.

Starting a Drush CLI is as easy as executing the following command:

$ drush core-cli
Entering the drush cli. Use CONTROL-D to exit.
Type 'help' for help.
drush>

Now we will load one of our site aliases and execute a few commands such as changing directory, listing files and clearing the cache:

drush> use @drupal.local
@drupal.local>
@drupal.local> cd %files
cd /home/juampy/projects/drupal/sites/default/files
@drupal.local> cd %root
cd /home/juampy/projects/drupal
@drupal.local> lsd %files
ls /home/juampy/projects/drupal/sites/default/files
styles
@drupal.local> cache-clear all
'all' cache was cleared [success]

Note in the previous commands how the prompt changed to our site alias (@drupal.local>) to denote that the commands would be executed against that site. We can list files or change directory using simple placeholders such as %root or %files. Furthermore, we do not even need to type drush when executing commands such as cache-clear.

In the following example, we will remove the current site alias from the prompt and clear the cache of a remote site. Then we will use that remote site alias to see how the prompt formats remote site aliases and clear the cache again:

@drupal.local> use
drush>
drush> @drupal.dev cache-clear all
'all' cache was cleared [success]
drush> use @festival.dev
festival.dev.drush:@festival.dev>
festival.dev.drush:@festival.dev> cache-clear all
'all' cache was cleared [success]

Saving Drush CLI configuration into our profile

If you always want to open terminal sessions with Drush CLI loaded, you can configure your terminal profile by adding the --pipe option to drush-cli and append the output to your $HOME/.bashrc file. We will first make a backup of .bashrc to easily roll back. The following is how:

$ cd $HOME
$ cp .bashrc .bashrc.backup
$ drush core-cli --pipe >> .bashrc
$ source .bashrc
$ use @drupal.local
@drupal.local> status
Drupal version : 7.12
Site URI : drupal.localhost
Database driver : mysql

We first copied $HOME/.bashrc to .bashrc.backup and then added Drush CLI configuration to it. The source command used next reloads our terminal session, thus loading the new configuration. That is why we could use a site alias and execute the status command against it. Now if you open a new terminal you will already have this configuration set up. If you ever want to get back to a normal terminal by default, rename .bashrc.backup to .bashrc.

Tip

If you have Shell scripting skills, read the output generated by drush core-cli --pipe to see if you want to customize it further.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.30.253