grahl/ch

Using Textexpander with Drupal

I’ve been using Textexpander for a while and recommend using a snippet tool very highly, especially if you have to deal with a significant amount of email, it’s a lifesaver. It’s also quite useful for development.

On the one hand you can save yourself time by creating shortcuts to heavily used commands. For most tools, such as Git, there are already existing collections out there but you can also easily and quickly create them with a few clicks yourself. Here’s one of my most used ones, which provides me with the cursor exactly where it needs to be to type in a commit message. (When I don’t want to auto-add, I just go to then end of the line and delete what’s there.)

git commit -m "%|" -a

One of my favorite ones is setting up a database. I do not want to deal with a third-party tool just to manage what amounts to creating a database a month and also not have to waste 2 minutes to get the syntax of this command right:

CREATE DATABASE %fill:database%; GRANT ALL PRIVILEGES ON %fill:database%.* TO '%fill:username%'@'%filltext:name=hostname:default=localhost%' IDENTIFIED BY '%fill:password%'; FLUSH PRIVILEGES;

Which then provides me with this nice dialog to focus on what’s important. It even automatically syncs the fields used twice (see the screenshot above).

Drupal development

When you are working on a Drupal project, the most automation often comes from abbreviating Drush even further and combining it with Git automation. Clear the cache, update, commit, etc.

For example, I use a snippet for “drush up –security-only -y” to update a repository, often calling that in several tabs at once for different projects. If it’s a contrib module, I have a wrapper script for automating this even further (I will provide that in a later post), however, core updates are seldom without minor reviews (did robots.txt or .htaccess change or override something, etc.). Thus, the following snippet does the stuff which should be uncritical, i.e. add files, remove versioning info, show me what’s left:

git add includes misc modules profiles scripts themes%key:enter%
rm CHANGELOG.txt COPYRIGHT.txt INSTALL.mysql.txt INSTALL.pgsql.txt INSTALL.sqlite.txt INSTALL.txt LICENSE.txt MAINTAINERS.txt README.txt UPGRADE.txt%key:enter%
git status%key:enter%

Textexpander is also quite useful, when you need to write PHPTemplate code. Since it’s inline PHP, even great IDE such as PHPStorm can’t autocomplete well and you are typing the same basic wrappers again and again. That’s not necessary. So, next time you want to print out a variable, a t() or maybe render an element, just use a snippet:

<?php print t('%|'); ?>

Should you have any problems with Textexpander behaving erratically in PHPStorm when you use cursor positioning or other modifications, have a look at this issue and set your clipboard retention to something such as 1.

Here are my Drush/Drupal snippets as of now.