NAME
Padre::Plugin::ShellCommand - A Shell Command plug-in
DESCRIPTION
This plug-in takes shell commands from the active document and inserts the output of the command into the document.
If text is selected then the plug-in will attempt to execute the selected text. If no text is selected the the plug-in will attempt to execute the current line as a command.
"Commands" can either be valid shell commands, entire scripts (with shebang), or environment variables to be evaluated.
There are two associated menu items:
- "Run Command" inserts the command output after the command while
- "Run Command Replace" replaces the command with the command output.
To assist in running shell commands this plug-in also sets some environment variables that may be of use to the commands being run. The following Padre Environment (PE_) are set.
- PE_BASENAME -- The file name of the current document.
- PE_DIRECTORY -- The directory of the current document.
- PE_FILEPATH -- The full path and name of the current document.
- PE_MIMETYPE -- The mime-type of the current document.
- PE_CONFIG_DIR -- Location of the configuration directory (~/.padre)
- PE_DEF_PROJ_DIR -- The default project directory.
- PE_INDENT_TAB -- Use tabs for indentation. 'YES' or 'NO'
- PE_INDENT_TAB_WIDTH -- Tab width/size.
- PE_INDENT_WIDTH -- Indentation width/size.
EXAMPLES
Example 1
Typing `$USER` on an otherwise blank line and invoking 'Run Command' without selecting anything would insert your user-name on the next line down.
$USER
gsiems
Example 2
Combinations of Environment variables and commands are also possible:
$USER was last seen on `date`
gsiems was last seen on Fri Oct 9 16:12:11 CDT 2009
Example 3
By typing, on an otherwise blank line, `The date is:` then selecting the word `date` and invoking 'Run Command' results in the date being inserted on the next line down.
The date is:
Fri Oct 9 16:12:11 CDT 2009
Example 4 (Mult-line scripts)
Typing a multi-line script, selecting the entire script and invoking 'Run Command' will run the entire selection as a shell script:
So:
for I in 1 2 3 ;
do
echo " and a $I"
done
Inserts:
and a 1
and a 2
and a 3
after the script block.
Example 5 (The whole shebang)
Shebangs are supported so the scripts aren't limited to shell commands/scripts.
For example, typing (and selecting) the following
#!/usr/bin/env perl
print " and a $_\n" for (qw(one two three));
and invoking 'Run Command' inserts:
and a one
and a two
and a three
after the script block.
Example 6 (PE_ variables)
Running the following:
#!/bin/sh
set | grep "^PE_"
Inserts something like:
PE_BASENAME=padre_test.pl
PE_CONFIG_DIR=/home/gsiems/.padre
PE_DEF_PROJ_DIR=/home/gsiems/projects
PE_DIRECTORY=/home/gsiems
PE_FILEPATH=/home/gsiems/padre_test.pl
PE_INDENT_TAB=NO
PE_INDENT_TAB_WIDTH=4
PE_INDENT_WIDTH=4
PE_MIMETYPE=application/x-perl
So, for instance, a user created script `mkheader` could use PE_BASENAME and PE_MIMETYPE to create an appropriate header for different file types.
LIMITATIONS
This plug-in will not work on operating systems that do not have an appropriate shell environment (such as MS Windows).
AUTHOR
Gregory Siems <gsiems@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2009 by Gregory Siems
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.