This task will cover how to execute shell commands directly from the current document.
The steps to execute shell commands directly from the current document are as follows:
Add a new command into the Bundle Editor window (Control + Option + Command + B) by clicking on the plus (+) icon and selecting New Command:
Fill in the Command(s) text field with the commands you wish to execute, along with the Input, Output, and Activation options. You can also select this option via the Bundles menu.
For the Command(s) text field, enter curl -sSd "css=$TM_SELECTED_TEXT" \http://prefixr.com/api/index.php for the Input option, set Selected Text or Document; for the Output option, set Replace Selected Text; and for the Activation option, set Key Equivalent and Control + Option + Command + U, as shown in the following screenshot:
Execute the command by selecting the text you wish to input. This is shown in the following screenshot:
And then use the chosen activation action (the keyboard shortcut Control + Option + Command + U in this example):
The example in this task uses Jeffery Way's Prefixr (http://www.prefixr.com/), which is a fantastic utility to make the CSS cross-browser compatible quickly and easily.
From the previous example, when you use the keyboard shortcut, the selected text (the input) will be sent to Prefixr via cURL (http://curl.haxx.se/), which is a command-line utility that transfers data from a variety of protocols, such as HTTP. The returned data (the output) will then replace the selected text.
Let's also look at how to execute commands from the document editor. Plus, we'll find out how to set environment variables to aid in development.
Another way to execute commands in TextMate is to execute the current line and return the results. This can be done from the menu (select Text | Execute Selection Inserting Result) or the keyboard shortcut Control + R:
In this section's example, we made use of the TextMate environment variable $TM_SELECTED_TEXT. There are a number of other similar environment variables that can be used for commands and more complex bundle operations. A full list of the variables can be found on Macromate's TextMate wiki:
You may also wish to utilize static shell variables (select Preferences | Advanced | Shell Variables), which you can use to declare usernames and passwords to your MySQL database or services such as Shopify (http://www.shopify.com/). The Shell Variables window is shown in the following screenshot:
You can also specify shell variables at the project level by clicking on the information icon in the Project Drawer menu, as shown in the following screenshot:
The Project Information window is shown in the following screenshot, where usernames and passwords of services such as MySQL can be set: