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:
3 chmod 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:
3 # Open the document's directory (just in case)
4 cd $GEDIT_CURRENT_DOCUMENT_DIR;
6 # Display information about script
7 echo -e "Running script: $GEDIT_CURRENT_DOCUMENT_NAME";
8 echo -e "\tin directory: $GEDIT_CURRENT_DOCUMENT_PATH";
9 echo -e "\n";
11 # Run script
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.
3 # Get parameters for command from user.
4 params=`zenity --entry --title="Run $GEDIT_CURRENT_DOCUMENT_NAME" --text="with these parameters"`
6 # Open the document's directory (just in case)
7 cd $GEDIT_CURRENT_DOCUMENT_DIR;
9 # Display information about script
10 echo -e "Running script: $GEDIT_CURRENT_DOCUMENT_NAME";
11 echo -e "\tin directory: $GEDIT_CURRENT_DOCUMENT_PATH";
12 echo -e "\twith params: $params";
13 echo -e "\n";
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.