Run Command Tutorial

 

Table of Contents

Using Command Shortcuts

You may often want to run a command on the current file, or in the directory of the current file. The Run Command feature makes this easy by providing a number of shortcuts for specifying things such as the current file or selection. With shortcuts, you can create more generic and useful commands. You can enter command shortcuts in the Run and Start in fields, or select them from the drop-down lists to the right of the Run and Start in fields. It is a good idea for Windows users to enclose all Komodo shortcuts (with the exception of %(browser)) in double quotation marks. This is necessary to ensure that any spaces in filenames or file paths are interpreted correctly.

Click the arrow button to the right of the Run field to view a list of Run Command shortcuts.

View Example

Shortcuts for the Current File

The string %F in a command will expand the full path of the current file.

  1. On the Projects tab, double-click the file play.txt. This file will be opened in the Editor Pane; a tab at the top of the pane displays its name.
  2. Select Tools|Run Command.
  3. In the Run field, enter the command:
    echo "%F"
  4. Click the Run button to run the command.

A more useful example is to make the current file read-only if it is writable.

  1. Open play.txt from your Run Command tutorial project if it is not already open.
  2. Select Tools|Run Command.
  3. In the Run field, enter the command:
    attrib +R "%F"
    on Windows, or:
    chmod u+w "%F"
    on Linux.
  4. Click the Run button to run the command. The result will be displayed at the top of the Command Output tab.

Or if you were editing an HTML file, you could combine %F with the %(browser) shortcut to open the current file in your Web browser.

  1. On the Projects tab, double-click the file index.html. This file will be opened in the Editor Pane; a tab at the top of the pane displays its name.
  2. Select Tools|Run Command.
  3. Click the arrow to the right the Run field to display the shortcuts drop-down list. Select %browser, press the space bar, and then select %F. Enclose the %F in double quotation marks.
  4. From the Run in drop-down menu, select No Console (GUI Application).
  5. Click the Run button to run the command.
Top

Shortcuts for the Current Selection

The %s, %S, %w and %W codes allow you to insert current selections, or the current word under your cursor, into commands. This can be very useful for running utilities like grep, or for searching the Web.

  1. On the Projects tab, double-click the file index.html. This file will be opened in the Editor Pane; a tab at the top of the pane displays its name.
  2. Position your cursor over the word "PHP" in the index.html document.
  3. Select Tools|Run Command.
  4. In the Run field, enter the command:
    %(browser) http://www.google.com/search?q="%W".
  5. Select the Add to Toolbox check box to save this command.
  6. Click the Run button to search for "PHP" with Google.

Now that you have a quick, easy way to look up a word or selection on Google, try the following shortcut as a fast way to search for PHP methods.

  1. Open index.html from your Run Command tutorial project if it is not already open.
  2. Select the text "mysql_info methods" in your document.
  3. Select Tools|Run Command.
  4. In the Run field, enter the command "%(browser) http://www.php.net/manual-lookup.php?pattern=%S".
  5. Select the Add to Toolbox check box to save this command.
  6. Click the Run button to look up "mysql_info methods" in PHP's online manual.

These two commands are so useful that both are built into Komodo. Ctrl+F1 will start a Google search for your current selection. Shift+F1 in a Perl, Python or PHP file will start a help search appropriate for that language. You can customize your searches in Komodo's Preferences dialog box (Edit|Preferences|Language Help).

Top

Using Shortcuts for a Command's Directory

The Run Command feature is very useful for running commands such as make, perl, or python. For example, you can use the command %(perl) "%F" to run your current file with your configured Perl interpreter. Often, however, these commands must run from the directory in which your current file is stored. By default, Komodo will run commands from Komodo's current directory, which is usually not the directory for the file you are editing. Fortunately, you can use command shortcuts in the Start in field of the Run Command dialog box.

  1. On the Projects tab, double-click the file hello.pl. This file will be opened in the Editor Pane; a tab at the top of the pane displays its name.
  2. Select Tools|Run Command.
  3. In the Run field, enter the command:
    %(perl) "%F"
  4. In the Start in field, enter: "%D"
  5. Click the Run button to run the command.

Note that this example assumes you have a perl interpreter configured. If you do not have a perl interpreter configured (the required file is perl.exe), an error message will be displayed at the top of the Command Output tab. Alternatively, you can run the command "dir" (Windows) or "ls" (Linux) to display a list of files and folders beneath the current directory.


Top Previous Next