Anyone who’s used TextExpander (or another system-wide text replacement tool) to save time when typing knows about its obvious uses, like canned email responses, auto-correcting misspelled words and inserting your mailing address.
But how can developers use text expansion tools in clever ways? We spend the majority of our day typing away in text editors and terminals, so surely there are things we can do to save keystrokes, remember lengthy commands and reinforce good coding habits. Plus, TextExpander’s ability to run shell commands and AppleScripts and write out the results could mean the end of repetitive typing for any Mac-using developer.
Below are a few ideas for how to speed up and improve your code-writing using text expansion. These tips work for TextExpander for Mac, but if you’re using Windows or Linux, there are several similar options available for you, including Texter, AutoHotkey, AutoKey and several others.
HTML, CSS and other code snippets
If you use TextMate or Vim snippets (which we’ve talked about before), this probably isn’t new to you, but in cases where you’re writing HTML in your browser or coding in a text editor that doesn’t support snippets, it’s a nice time-saver.
Quicker, safer SQL queries
The vast majority of the SQL queries I write are simple, throwaway SELECTs, UPDATEs and INSERTs. Using a TextExpander fill-in template, I type
sqli to create generic SQL queries to start with. And, just to be safe, I include a
BEGIN; line with any data-modifying query snippets so I don’t accidentally change everyone’s first name to Zebediah in an Emma account’s contact list.
Remember long terminal commands
I will never remember how to restart my local Redis instance or run my test Postgres server without looking up a command I wrote down somewhere. I don’t do it every day, so it’s hard to commit to memory. Typing
,ppsql is much easier to remember than
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start and saves me a few seconds of thinking and typing.
In this case I could just as easily use .bashrc aliases, but I prefer TextExpander because my snippet will expand before I run it so I can make sure I’m running the right command and tweak arguments as needed.
You could also use fill-in snippets to run subsets of test suites, make a REST call to a copied URL with cURL, grep for lines in a file containing a piece of text in your clipboard or use wget to download all files of a particular type from a URL.
Create unique, throwaway email addresses
Lately I’ve been working on adding and editing members in the Emma app, which means I have to come up with a bunch of unique email addresses to add to my account, preferably all addresses that redirect to my inbox. Luckily, many email providers (including ours) ignore anything after the plus character in an email username, so I use that to my advantage by using TextExpander to add a timestamp after my email username:
Using the Internet Productivity Snippets group that comes with TextExpander, typing
/bitly will shorten a URL you just copied to your clipboard and write out the new bit.ly URL.
Format copied text
Maybe you need to URL encode a string, hyphenate a bunch of words together or remove all HTML tags from something in your clipboard. Thanks to regular expressions and text formatting libraries in Python, Ruby, Perl or any other scriptable language, this is easy as pie. As an example to start with, here’s a shell script snippet that will write out a hyphenated version of whatever text is in your clipboard:
pbpaste | sed 's/ /\-/g'
Similarly, an article on Macworld suggests writing a shell script snippet to take formatted text copied from your browser or word processor, run it through Plain Clip to reformat it as plaintext, then write out the cleaned-up output.
Of course, these ideas only scratch the surface of what’s possible. Every developer’s day looks a little bit different and text expansion can easily automate some of the typing you (and perhaps only you) are doing every day. What are some ways you use TextExpander to develop better, faster and safer?