gedit external tools: adding perl and python

Teaching the kid python today and decided it would be nice to be able to run scripts from within gedit the way I do my perl scripts at work. Here’s the recipe.

The current official text editor for the gnome environment is gedit. Although it has its shortcomings, I’ve gotten used to working with it as my primary editor at work and home. While most Linux distros ship it with the plugin for a python console, you have to do a little configuring to get the kind of one-stop point-and-click-to-execute convenience found in most IDE’s.

Making this work in gedit is pretty easy though.

First, make sure the External Tools plugin is installed and enabled To do this go to Edit … Preferences… Plugins.

Once you’ve made sure the box is checked, click Configure.

Click on the suspiciously unlabelled button in the lower left hand corner to bring up the “New Tool” dialog (see that trash can button to the right, it will be your eternal friend — take it from me).

Click on “New Tool” again, because that’s not what you’re going to want to call this. Instead type in “Python”.

Replace the shebang (#!/bin/sh) with the following:

/usr/bin/python $GEDIT_CURRENT_DOCUMENT_PATH


This tells gedit to use python to execute your current document with the python interpreter when you select this tool.

To use the new tool, just open up a script in gedit and then select “Tools… External Tools … Python. Program output appears in a window that open up in the bottom half of the editor.

In addition to python, I’ve also got gedit to let me execute perl scripts from within the editor.