Scripting in gedit

Hey. I didn't know this before, but you can run your own scripts out of gedit. Well, obviously, I was vaguely aware that this was possible, but I didn't know it was so gorram easy! So I've made some scripts that would help me script in the future.

All these scripts are installed by going to Tools > Extrenal Tools, then pressing New and then filling out the fields - most importantly, the Command(s) field.

Ok, here's what I've concocted.

First of all, I didn't want to go to the command line every time I want to make something executable, so there's this:

1#!/bin/bash
2
3chmod a+x $GEDIT_CURRENT_DOCUMENT_PATH 


It's pretty self explanatory, methinks.

Then, I wanted to run a script from gedit, so I did this script:

#!/bin/bash

# Open the document's directory (just in case)
cd $GEDIT_CURRENT_DOCUMENT_DIR;

# Display information about script
echo -e "Running script: $GEDIT_CURRENT_DOCUMENT_NAME";
echo -e "\tin directory: $GEDIT_CURRENT_DOCUMENT_PATH";
echo -e "\n";
10
11# Run script
12$GEDIT_CURRENT_DOCUMENT_PATH;


It's mostly straightforward (just follow the comments). It displays a lot of info, because I'm the kind of guy who forgets what he ran just a second ago and needs constant reminding.

Finally, I added the ability to insert parameters with a GUI. I stole this concept from one of those default scripts that are put into gedit.

#!/bin/bash

# Get parameters for command from user.
params=`zenity --entry --title="Run $GEDIT_CURRENT_DOCUMENT_NAME" --text="with these parameters"`

# Open the document's directory (just in case)
cd $GEDIT_CURRENT_DOCUMENT_DIR;

# Display information about script
10echo -e "Running script: $GEDIT_CURRENT_DOCUMENT_NAME";
11echo -e "\tin directory: $GEDIT_CURRENT_DOCUMENT_PATH";
12echo -e "\twith params: $params";
13echo -e "\n";
14
15# Run script
16$GEDIT_CURRENT_DOCUMENT_PATH $params;


Here, in line 4 I call zenity to gather the parameters from the user and then just stick them to the end of the name of the script. Simple!

Hope this comes in handy.

The code is also available at GitHub in the directory gedit.

lala moulati ana9a maghribia

seo

 

Blogroll

Site Info

Text

telechargementz Copyright © 2009 WoodMag is Designed by Ipietoon for Free Blogger Template