Terminus Command Line Tool

Here are some shortcuts you may find useful for working with Pantheon sites on the command line. Modify the PANTHEON_SITES array of this script and place it in your shell profile or rc file (e.g., ~/.bash_profile or ~/.bashrc):

# PANTHEON: Terminus site shortcuts.
# Use short, keyboard-friendly site names for the array keys, and specify the full Pantheon site machine names as array values.
declare -A PANTHEON_SITES
PANTHEON_SITES[mysite]=my-pantheon-site
PANTHEON_SITES[client]=client-pantheon-site
for site in "${!PANTHEON_SITES[@]}" ; do
  eval "${site} () {
    terminus drush ${PANTHEON_SITES[${site}]}.\$1 -- \${@:2}
  }"
  eval "${site}-db () {
    URL=\"\$(terminus backup:get --element=database ${PANTHEON_SITES[${site}]}.live -- \${@})\"
    wget -O ${site}.sql.gz \"\${URL}\"
  }"
done
# END PANTHEON

For each site key defined in the PANTHEON_SITES variable, you will have two shortcuts available on the command line (after opening a new terminal window to make sure the changes are loaded):

  1. <alias> <env> <drush-command> will execute a drush command in a given environment. E.g., mysite test cc all will clear caches in the test environment of my-pantheon-site (per example alias set up in the code block above).
  2. <alias>-db accepts no arguments and simply downloads the latest database backup from the live environment. E.g., mysite-db downloads the latest database backup of the live environment from my-pantheon-site to mysite.sql.gz (per example alias set up in the code block above) in the current directory. If you regularly download databases from other environments, you can easily modify the shell script to accept a parameter instead of hard-coding live as the target environment.

Enjoy!