NAME
Padre::Plugin::Shell::Command - The Shell Command plug-in functions
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 three associated menu items:
- "Run Command, Insert" inserts the command output after the command while
- "Run Command, Replace" replaces the command with the command output.
- "Run Command, New" creates a new document with the command output.
ENVIRONMENT VARIABLES
To provide additional information for the filters, various environment variables are set prior to running the filter. These environment variables are covered in the Padre::Plugin::Shell::Base documentation.
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.
METHODS
get_cmd ($editor)
Determines and returns the command is that is to be run.
plugin_menu
Returns a menu items for the plugin.
run_command ($action)
Runs the command and performs the appropriate $action with the result.
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.