Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have installed the Better Python Console-Plugin for gedit and I am happy with it when I view python code. But I would like to be able to execute some different languages source codes when I have opened it in gedit.

For example, I would like to run $ g++ filename.cpp -o filename.out; ./filename.out if I hit F5 while I have opened a C++-file. If I have opened a PHP-file I don't want to happen anything at all.

Is this possible?

share|improve this question
    
I see that you've asked two questions but only voted once. If you accept an answer you probably find it useful, then you should also upvote it. –  N.N. Aug 24 '11 at 19:06
add comment

1 Answer 1

up vote 0 down vote accepted

This can be done with the external tools in gedit. They're found under Tools.

Create a new external tool and paste the following code into it:

#!/bin/sh

GEDIT_CURRENT_DOCUMENT_NAME_ROOT=`echo $GEDIT_CURRENT_DOCUMENT_NAME | sed 's/\(.*\)\.tex$/\1/'`
g++ $GEDIT_CURRENT_DOCUMENT_NAME_ROOT.cpp -o $GEDIT_CURRENT_DOCUMENT_NAME_ROOT.out; ./$GEDIT_CURRENT_DOCUMENT_NAME_ROOT.out

Then bind a Shortcut Key, in your case F5, to this tool.

And, finally press the three dots in the lower right corner (right of Applicability) and choose an option so that it only applies to C++ files.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.