public function writeDrushAlias()
    {
        $drush_alias_file_path = "{$_SERVER['HOME']}/.drush/terra.{$this->app->name}.aliases.drushrc.php";

        $drush_alias_file = array();
        $drush_alias_file[] = '<?php';

        foreach ($this->app->environments as $environment_name => $environment) {
            $factory = new self($environment, $this->app);
            $path = "/app/" . $environment['document_root'];
            $drush_alias_file[] = '// DO NOT EDIT. This is generated by Terra. Any changes will be overridden when the environment is re-enabled.';
            $drush_alias_file[] = "\$aliases['{$environment_name}'] = array(";
            $drush_alias_file[] = "  'uri' => '{$factory->getHost()}:{$factory->getPort()}',";
            $drush_alias_file[] = "  'root' => '$path',";
            $drush_alias_file[] = "  'remote-host' => '{$factory->getHost()}',";
            $drush_alias_file[] = "  'remote-user' => 'terra',";
            $drush_alias_file[] = "  'ssh-options' => '-p {$factory->getDrushPort()}',";
            $drush_alias_file[] = ');';
        }

        $fs = new FileSystem();

        try {
            $fs->dumpFile($drush_alias_file_path, implode("\n", $drush_alias_file));

            return true;
        } catch (IOException $e) {
            return false;
        }
    }