redcar-filter-through-command 1.3.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +119 -0
- data/changes.md +22 -0
- data/lib/filter_command/autocompletion.rb +42 -0
- data/lib/filter_command/command_parser.rb +58 -0
- data/lib/filter_command/commands.rb +36 -0
- data/lib/filter_command/evaluator.rb +118 -0
- data/lib/filter_command/filter_speedbar.rb +70 -0
- data/lib/filter_command/formats/discard.rb +12 -0
- data/lib/filter_command/formats/insert.rb +40 -0
- data/lib/filter_command/formats/replace.rb +29 -0
- data/lib/filter_command/formats/show.rb +44 -0
- data/lib/filter_command/history.rb +61 -0
- data/lib/filter_command/output_format.rb +62 -0
- data/lib/filter_command.rb +56 -0
- data/license +9 -0
- data/plugin.rb +8 -0
- metadata +129 -0
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
#✩‿✩ Filter Through Command
|
2
|
+
_A Redcar Editor plugin for manipulating and displaying text using shell commands_
|
3
|
+
|
4
|
+
**Filter Through Command** supports running the current line of a document as a shell script, as well as manipulating and displaying text using several options for input and output.
|
5
|
+
|
6
|
+
|
7
|
+
##Installation
|
8
|
+
|
9
|
+
Version 1.0 supports Redcar 0.8 and above, versions 1.1 and beyond support Redcar 0.12 and above only.
|
10
|
+
|
11
|
+
###Redcar v0.12 and above:
|
12
|
+
|
13
|
+
gem install redcar-filter-through-command
|
14
|
+
|
15
|
+
|
16
|
+
alternately, you can install from source:
|
17
|
+
|
18
|
+
###Redcar v0.8 to v0.11:
|
19
|
+
|
20
|
+
Download a build from the Downloads section and copy to `~/.redcar/plugins`, or build from source:
|
21
|
+
|
22
|
+
cd ~/.redcar/plugins
|
23
|
+
git clone git://github.com/kattrali/redcar-filter-through-command.git filter_through_command
|
24
|
+
git fetch origin --tags
|
25
|
+
git checkout 1.0 # or 1.1, etc
|
26
|
+
|
27
|
+
|
28
|
+
##Usage
|
29
|
+
|
30
|
+
### Running the current line or selection as a shell script
|
31
|
+
|
32
|
+
Select `Plugins > Filter Through Command > Evaluate Text` to run the cursor line or selection as a shell script.
|
33
|
+
|
34
|
+
![Evaluating a text as shell command](https://github.com/kattrali/redcar-filter-through-command/raw/master/docs/images/run%20command.png)
|
35
|
+
|
36
|
+
### Filtering text through a shell script
|
37
|
+
|
38
|
+
Select `Plugins > Filter Through Command > Open Speedbar...` to view command filtering options.
|
39
|
+
Press the `Execute` button or press `Return` in the Command field to run a shell command with the selected options. To rerun the last used filter options, select `Plugins > Filter Through Command > Re-run Last Filter`, or use the keyboard shortcuts.
|
40
|
+
|
41
|
+
**Autocompletion** is available for recently run commands, and the 10 most recent commands are available from the Command menu.
|
42
|
+
|
43
|
+
####Input Options
|
44
|
+
|
45
|
+
<table style="border:none">
|
46
|
+
<tbody>
|
47
|
+
<tr><td><strong>None</strong></td><td>Run a command without input</td></tr>
|
48
|
+
<tr><td><strong>Cursor Line</strong></td><td>Run a command using the text of the cursor line as input</td></tr>
|
49
|
+
<tr><td><strong>Cursor Word</strong></td><td>Run a command with the word containing the cursor as input</td></tr>
|
50
|
+
<tr><td><strong>Document</strong></td><td>Run a command with all of the text of the current document given as input</td></tr>
|
51
|
+
<tr><td><strong>Selection</strong></td><td>Run a command with the selected text or the cursor line text given as input</td></tr>
|
52
|
+
</tbody>
|
53
|
+
</table>
|
54
|
+
|
55
|
+
####Output Options
|
56
|
+
|
57
|
+
<table style="border:none">
|
58
|
+
<tbody>
|
59
|
+
<tr><td><strong>Create new Document</strong></td><td>Insert output into a new document</td></tr>
|
60
|
+
<tr><td><strong>Discard</strong></td><td>Ignore output</td></tr>
|
61
|
+
<tr><td><strong>Insert as Text</strong></td><td>Insert output into the current document at the cursor</td></tr>
|
62
|
+
<tr><td><strong>Open as URL</strong></td><td>Open the output in a web browser as a URL</td></tr>
|
63
|
+
<tr><td><strong>Replace Document</strong></td><td>Replace the entire document with output</td></tr>
|
64
|
+
<tr><td><strong>Replace Selection</strong></td><td>Replace the selected text with output</td></tr>
|
65
|
+
<tr><td><strong>Show as HTML</strong></td><td>Open the output in a new HtmlTab or in the default browser</td></tr>
|
66
|
+
<tr><td><strong>Show as Popup</strong></td><td>Open the output in a popup dialog under the selected text or cursor line</td></tr>
|
67
|
+
<tr><td><strong>Show as HTML Popup</strong></td><td>Open the output in a popup dialog formatted as HTML</td></tr>
|
68
|
+
</tbody>
|
69
|
+
</table>
|
70
|
+
|
71
|
+
####Variable Substitution
|
72
|
+
|
73
|
+
Filter through Command also provides substitution variables for commonly needed text in commands. Substitutions can be further shortened to # + lower case first letter. (Scope being the exception, instead using `#c`.)
|
74
|
+
|
75
|
+
<table style="border:none">
|
76
|
+
<tbody>
|
77
|
+
<tr><td><strong>DOCUMENT (#d)</strong></td><td>All of the text of the current document</td></tr>
|
78
|
+
<tr><td><strong>LINE (#l)</strong></td><td>Text of the cursor line</td></tr>
|
79
|
+
<tr><td><strong>FILE_PATH (#f)</strong></td><td>The file path to the current document</td></tr>
|
80
|
+
<tr><td><strong>SELECTION (#s)</strong></td><td>Text of the current selection</td></tr>
|
81
|
+
<tr><td><strong>TEMP (#t)</strong></td><td>A new empty file, which is afterwards opened by Redcar</td></tr>
|
82
|
+
<tr><td><strong>WORD (#w)</strong></td><td>Text of the word containing the cursor</td></tr>
|
83
|
+
<tr><td><strong>SCOPE (#c)</strong></td><td>The current scope of the cursor</td></tr>
|
84
|
+
</tbody>
|
85
|
+
</table>
|
86
|
+
|
87
|
+
|
88
|
+
##Extending this Plugin
|
89
|
+
|
90
|
+
Additional output types can be added by subclassing `FilterCommand::OutputFormat` and implementing the `supported_types` and `format(text,type)` methods, then including the new class in a Redcar plugin. Examples can be found in `lib/filter_command/formats`.
|
91
|
+
|
92
|
+
|
93
|
+
##Screenshots
|
94
|
+
|
95
|
+
![HTML Text before conversion to HAML](https://github.com/kattrali/redcar-filter-through-command/raw/redcar-0.12/docs/images/before.png)
|
96
|
+
|
97
|
+
![HTML Text after conversion to HAML](https://github.com/kattrali/redcar-filter-through-command/raw/redcar-0.12/docs/images/after.png)
|
98
|
+
|
99
|
+
_Converting HTML to Haml_
|
100
|
+
|
101
|
+
![Example of HTML output](https://github.com/kattrali/redcar-filter-through-command/raw/master/docs/images/html%20output.png)
|
102
|
+
|
103
|
+
_HTML Output_
|
104
|
+
|
105
|
+
![Example of Popup output](https://github.com/kattrali/redcar-filter-through-command/raw/master/docs/images/popup%20output.png)
|
106
|
+
|
107
|
+
_Popup Output_
|
108
|
+
|
109
|
+
![Example of HTML Popup Output](https://github.com/kattrali/redcar-filter-through-command/raw/master/docs/images/html%20popup%20output.png)
|
110
|
+
|
111
|
+
_HTML Popup_
|
112
|
+
|
113
|
+
![Example of Autocompletion](https://github.com/kattrali/redcar-filter-through-command/raw/redcar-0.12/docs/images/autocomplete.png)
|
114
|
+
|
115
|
+
_Autocompletion_
|
116
|
+
|
117
|
+
![Example of Substitution](https://github.com/kattrali/redcar-filter-through-command/raw/redcar-0.12/docs/images/substitution.png)
|
118
|
+
|
119
|
+
_Using Variable Substitution_
|
data/changes.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Changelog
|
2
|
+
=========
|
3
|
+
|
4
|
+
##1.3
|
5
|
+
|
6
|
+
* Added cursor line and cursor word as input types
|
7
|
+
|
8
|
+
##1.2
|
9
|
+
|
10
|
+
* Added variable substitutions, like #d to insert the current document text and #f for the current file path
|
11
|
+
* Set command area font to match editable tabs
|
12
|
+
* Typed commands autocomplete from recently entered commands
|
13
|
+
|
14
|
+
##1.1
|
15
|
+
|
16
|
+
* Required Redcar version bumped to 0.12
|
17
|
+
* Added command history
|
18
|
+
* Saved commands also save input and output parameters
|
19
|
+
|
20
|
+
##1.0
|
21
|
+
|
22
|
+
Initial Version
|
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class FilterCommand
|
4
|
+
# Command auto-completion manager
|
5
|
+
class Autocompletion
|
6
|
+
|
7
|
+
# Provides command suggestions for text snippets
|
8
|
+
# based on previously run commands
|
9
|
+
# @param [String] text the start of a command
|
10
|
+
# @return [Hash] a hash containing a command beginning with the given text, an input type, an output type, and which characters of the text to select.
|
11
|
+
def self.suggest text
|
12
|
+
match, completion,selection = nil
|
13
|
+
if text.length > 0
|
14
|
+
FilterCommand::History.recent_commands.each do |map|
|
15
|
+
if map['command'] == text
|
16
|
+
match = map unless match
|
17
|
+
elsif map['command'][0,text.length] == text
|
18
|
+
completion = map unless completion
|
19
|
+
end
|
20
|
+
end
|
21
|
+
if completion and not match
|
22
|
+
if !@typed or @typed != text
|
23
|
+
match = completion
|
24
|
+
selection = [text.length,match['command'].length]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
@typed = text
|
28
|
+
if match
|
29
|
+
{
|
30
|
+
'command' => match['command'],
|
31
|
+
'input_type' => match['input_type'],
|
32
|
+
'output_type' => match['output_type'],
|
33
|
+
'selection' => selection
|
34
|
+
}
|
35
|
+
end
|
36
|
+
else
|
37
|
+
@typed_length = nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class FilterCommand
|
4
|
+
# Finds, evaluates and replaces supported Redcar environment
|
5
|
+
# variables in shell commands
|
6
|
+
class CommandParser
|
7
|
+
|
8
|
+
# A list of supported variables
|
9
|
+
def self.supported_variables
|
10
|
+
['SELECTION','DOCUMENT','WORD','LINE','SCOPE']
|
11
|
+
end
|
12
|
+
|
13
|
+
# Sets and inserts supported variables into the shell command enviroment
|
14
|
+
# and replaces shortened substitution characters
|
15
|
+
# @param [Redcar::Document] doc a document for use in the current command
|
16
|
+
# @param [String] command the command to be executed
|
17
|
+
def self.substitute_variables doc, command
|
18
|
+
output = {}
|
19
|
+
ENV['REDCAR_SELECTION'] = doc.selected_text if doc.selection?
|
20
|
+
ENV['REDCAR_DOCUMENT'] = doc.get_all_text
|
21
|
+
ENV['REDCAR_WORD'] = doc.current_word
|
22
|
+
ENV['REDCAR_LINE'] = doc.get_line(doc.cursor_line)
|
23
|
+
ENV['REDCAR_SCOPE'] = doc.cursor_scope
|
24
|
+
supported_variables.each do |var|
|
25
|
+
unless ENV['REDCAR_'+var].nil?
|
26
|
+
var_alias = var == 'SCOPE' ? '#c' : /(##{var.downcase.split(//).first})(\W|\z)/
|
27
|
+
var_env = to_env(var,Redcar.platform)
|
28
|
+
command = command.gsub(var,var_env).gsub(var_alias,"#{var_env}\\2")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
if doc.mirror and doc.mirror.respond_to?(:path) and path = doc.mirror.path
|
32
|
+
path = "\\\\\"#{path}\\\\\""
|
33
|
+
command = command.gsub('FILE_PATH',path).gsub(/(#f)(\W|\z)/,"#{path}\\2")
|
34
|
+
end
|
35
|
+
if command.include?('TEMP') or command =~ /(#t)(\W|\z)/
|
36
|
+
temp = java.io.File.create_temp_file("tempfile",".txt")
|
37
|
+
temp.delete_on_exit
|
38
|
+
path = temp.get_absolute_path
|
39
|
+
output['temp'] = path
|
40
|
+
path = "\\\\\"#{path}\\\\\""
|
41
|
+
command = command.gsub('TEMP',path).gsub(/(#t)(\W|\z)/,path)
|
42
|
+
end
|
43
|
+
output['command'] = command
|
44
|
+
output
|
45
|
+
end
|
46
|
+
|
47
|
+
# Proper escaping for environment variables (platform-specific)
|
48
|
+
def self.to_env variable, platform
|
49
|
+
case platform
|
50
|
+
when :windows
|
51
|
+
return "%REDCAR_#{variable}%"
|
52
|
+
when :linux,:osx
|
53
|
+
return "\\\\\"$REDCAR_#{variable}\\\\\""
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class FilterCommand
|
4
|
+
# Opens a filter speedbar in the current window
|
5
|
+
class OpenFilterSpeedbar < Redcar::Command
|
6
|
+
def execute
|
7
|
+
window = Redcar.app.focussed_window
|
8
|
+
speedbar = Redcar::FilterCommand::FilterSpeedbar.new
|
9
|
+
window.open_speedbar(speedbar)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Reruns the last filter command, if available
|
14
|
+
class RerunLastFilter < Redcar::Command
|
15
|
+
def execute
|
16
|
+
if command = FilterCommand.command and
|
17
|
+
output = FilterCommand.output_type and
|
18
|
+
input = FilterCommand.input_type
|
19
|
+
FilterCommand::Evaluator.evaluate(command,input,output)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Evaluates the currently selected text or cursor line as a shell command
|
25
|
+
class EvaluateText < Redcar::EditTabCommand
|
26
|
+
def execute
|
27
|
+
if doc.selection?
|
28
|
+
command = doc.selected_text
|
29
|
+
else
|
30
|
+
command = doc.get_line_without_end_of_line(doc.cursor_line)
|
31
|
+
end
|
32
|
+
FilterCommand::Evaluator.evaluate(command,"None",FilterCommand.output_type)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class FilterCommand
|
4
|
+
# The command parser and runner for FilterCommand
|
5
|
+
class Evaluator
|
6
|
+
|
7
|
+
# List of supported input types for command execution
|
8
|
+
def self.input_types
|
9
|
+
['None','Selection','Document','Cursor Line','Cursor Word']
|
10
|
+
end
|
11
|
+
|
12
|
+
# Command processing before execution. If successful,
|
13
|
+
# the given command is run.
|
14
|
+
# @param [String] command the command to run
|
15
|
+
# @param [String] input the selected input format
|
16
|
+
# @param [String] output the selected output format
|
17
|
+
def self.evaluate(command,input,output)
|
18
|
+
win = Redcar.app.focussed_window
|
19
|
+
tab = win.focussed_notebook_tab
|
20
|
+
original_command = command.clone
|
21
|
+
unless input == "None"
|
22
|
+
if tab and tab.is_a?(Redcar::EditTab) and doc = tab.edit_view.document
|
23
|
+
case input
|
24
|
+
when "Selection"
|
25
|
+
if doc.selection?
|
26
|
+
selection = doc.selected_text
|
27
|
+
else
|
28
|
+
selection = doc.get_line_without_end_of_line(doc.cursor_line)
|
29
|
+
end
|
30
|
+
command = pipe_text(selection, command)
|
31
|
+
when "Document"
|
32
|
+
command = pipe_text(doc.get_all_text, command)
|
33
|
+
when "Cursor Line"
|
34
|
+
command = pipe_text(doc.get_line_without_end_of_line(doc.cursor_line), command)
|
35
|
+
when "Cursor Word"
|
36
|
+
command = pipe_text(doc.current_word, command)
|
37
|
+
else
|
38
|
+
raise "Unknown input type found: #{input}"
|
39
|
+
end
|
40
|
+
result = FilterCommand::CommandParser.substitute_variables(doc,command)
|
41
|
+
command = result['command']
|
42
|
+
temp = result['temp']
|
43
|
+
else
|
44
|
+
tab_type_error input
|
45
|
+
return
|
46
|
+
end
|
47
|
+
end
|
48
|
+
execute_command win, command, input, output
|
49
|
+
if temp and File.exist?(temp)
|
50
|
+
Redcar::Project::Manager.open_file(temp)
|
51
|
+
end
|
52
|
+
FilterCommand::History.update_commands original_command, input, output
|
53
|
+
end
|
54
|
+
|
55
|
+
# The actual running of a command
|
56
|
+
# @param [Redcar::Window] window a Redcar window, generally the window containing the
|
57
|
+
# filter speedbar. If the current window has a project open, the process working directory
|
58
|
+
# will be the project directory.
|
59
|
+
# @param [String] command the command to be executed
|
60
|
+
# @param [String] input the selected input format
|
61
|
+
def self.execute_command window, command, input, output
|
62
|
+
if project = Project::Manager.in_window(window)
|
63
|
+
command = set_path command, project.path
|
64
|
+
end
|
65
|
+
pid, io_input, io_output, io_error = IO.popen4(command)
|
66
|
+
if error = io_error.read and error.empty?
|
67
|
+
format_text(io_output.read, output)
|
68
|
+
else
|
69
|
+
Redcar::Application::Dialog.message_box(error, :type => :error)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Command post-processing.
|
74
|
+
# @param [String] text the text output of the the command process
|
75
|
+
# @param [String] output the selected output format
|
76
|
+
def self.format_text text, format
|
77
|
+
if format_class = OutputFormat.formats[format]
|
78
|
+
format_class.new.format(text,format)
|
79
|
+
else
|
80
|
+
raise "Unknown output type found: #{format}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Sets the working directory for a given command to a given path,
|
85
|
+
# and adds proper escaping (platform-specific).
|
86
|
+
# @param [String] command the command to be executed
|
87
|
+
# @param [String] path the desired running directory
|
88
|
+
def self.set_path command, path
|
89
|
+
case Redcar.platform
|
90
|
+
when :osx, :linux
|
91
|
+
command = "sh -c \"cd \\\"#{path}\\\" && #{command}\""
|
92
|
+
when :windows
|
93
|
+
command = "cd \"#{path.gsub('/', '\\')}\" & #{command}"
|
94
|
+
end
|
95
|
+
command
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def self.tab_type_error type
|
101
|
+
Redcar::Application::Dialog.message_box(
|
102
|
+
"This command currently cannot be run with #{type} as the Input type." +
|
103
|
+
" The focussed tab is not an editable tab.")
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.pipe_text text, command
|
107
|
+
ENV['REDCAR_FILTER_TEXT'] = text
|
108
|
+
case Redcar.platform
|
109
|
+
when :osx, :linux
|
110
|
+
command = "echo \\\"$REDCAR_FILTER_TEXT\\\" | #{command}"
|
111
|
+
when :win
|
112
|
+
command = "echo %REDCAR_FILTER_TEXT% | #{command}"
|
113
|
+
end
|
114
|
+
command
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class FilterCommand
|
4
|
+
class FilterSpeedbar < Redcar::Speedbar
|
5
|
+
include Redcar::Observable
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
win = Redcar.app.focussed_window
|
9
|
+
if win and tab = win.focussed_notebook_tab and tab.is_a?(Redcar::EditTab)
|
10
|
+
command.value = tab.edit_view.document.selected_text
|
11
|
+
input = 'None'
|
12
|
+
end
|
13
|
+
set_commands
|
14
|
+
input_type.items = FilterCommand::Evaluator.input_types
|
15
|
+
input_type.value = input || FilterCommand::History.input_type
|
16
|
+
output_type.items = FilterCommand::OutputFormat.formats.keys.sort
|
17
|
+
output_type.value = FilterCommand::History.output_type
|
18
|
+
end
|
19
|
+
|
20
|
+
def set_commands
|
21
|
+
command.items = FilterCommand::History.command_list[0..10]
|
22
|
+
command.value = FilterCommand::History.command
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_font
|
26
|
+
@font = Swt::Graphics::Font.new(
|
27
|
+
ApplicationSWT.display,
|
28
|
+
EditView.font,
|
29
|
+
EditView.font_size,
|
30
|
+
Swt::SWT::NORMAL)
|
31
|
+
win = Redcar.app.focussed_window
|
32
|
+
@command_widget = win.speedbar.controller.focussable_widgets.first
|
33
|
+
@command_widget.font = @font
|
34
|
+
end
|
35
|
+
|
36
|
+
def close
|
37
|
+
@command_widget = nil
|
38
|
+
@font.dispose if @font and not @font.disposed?
|
39
|
+
end
|
40
|
+
|
41
|
+
label :command_label, "Command:"
|
42
|
+
combo :command, [], "", true do
|
43
|
+
set_font unless @font
|
44
|
+
if completion = FilterCommand::Autocompletion.suggest(command.value)
|
45
|
+
input_type.value = completion['input_type']
|
46
|
+
output_type.value = completion['output_type']
|
47
|
+
command.value = completion['command']
|
48
|
+
@command_widget.text = completion['command']
|
49
|
+
if selection = completion['selection']
|
50
|
+
point = Swt::Graphics::Point.new(selection.first,selection.last)
|
51
|
+
@command_widget.selection = point
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
label :input_label, "Input:"
|
57
|
+
combo :input_type
|
58
|
+
|
59
|
+
label :output_label, "Output:"
|
60
|
+
combo :output_type
|
61
|
+
|
62
|
+
button :execute, "Execute", "Return" do
|
63
|
+
unless command.value.empty?
|
64
|
+
FilterCommand::Evaluator.evaluate(command.value, input_type.value, output_type.value)
|
65
|
+
set_commands
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class FilterCommand
|
4
|
+
|
5
|
+
# Output formats for inserting command output into a document.
|
6
|
+
# Currently supported formats are 'Insert as Text' and 'Create new Document'
|
7
|
+
class InsertOutput < OutputFormat
|
8
|
+
supported_types "Insert as Text", "Create new Document"
|
9
|
+
|
10
|
+
def format text, type
|
11
|
+
case type
|
12
|
+
when "Insert as Text"
|
13
|
+
if edit_tab_focussed?
|
14
|
+
if doc = tab.edit_view.document
|
15
|
+
if doc.selection?
|
16
|
+
line = doc.line_at_offset(doc.selection_range.last)
|
17
|
+
offset = doc.offset_at_line_end(line)
|
18
|
+
else
|
19
|
+
offset = doc.cursor_line_end_offset
|
20
|
+
end
|
21
|
+
unless doc.get_line(doc.line_at_offset(offset)).to_java.ends_with newline
|
22
|
+
text = "#{newline}#{text}"
|
23
|
+
end
|
24
|
+
doc.insert(offset,text)
|
25
|
+
doc.cursor_offset = offset + text.length
|
26
|
+
end
|
27
|
+
else
|
28
|
+
missing_edit_tab(type)
|
29
|
+
end
|
30
|
+
when "Create new Document"
|
31
|
+
win = Redcar.app.focussed_window
|
32
|
+
tab = win.new_tab(Redcar::EditTab)
|
33
|
+
tab.edit_view.document.text = text
|
34
|
+
tab.edit_view.reset_undo
|
35
|
+
tab.focus
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class FilterCommand
|
4
|
+
# Output formats for replacing text in the current document
|
5
|
+
# Currently supported outputs are 'Replace Selection' and 'Replace Document'
|
6
|
+
class ReplaceInput < OutputFormat
|
7
|
+
supported_types "Replace Selection", "Replace Document"
|
8
|
+
|
9
|
+
def format text, type
|
10
|
+
if edit_tab_focussed?
|
11
|
+
case type
|
12
|
+
when "Replace Selection"
|
13
|
+
doc = tab.edit_view.document
|
14
|
+
if doc.selection?
|
15
|
+
doc.replace_selection text
|
16
|
+
else
|
17
|
+
text= text+newline unless text.to_java.ends_with newline
|
18
|
+
doc.replace_line(doc.cursor_line,text)
|
19
|
+
end
|
20
|
+
when "Replace Document"
|
21
|
+
tab.edit_view.document.text = text
|
22
|
+
end
|
23
|
+
else
|
24
|
+
missing_edit_tab(type)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class FilterCommand
|
4
|
+
# An output format for displaying command output to the user
|
5
|
+
# in a specially-formatted way.
|
6
|
+
# Supported Formats:
|
7
|
+
# - Show as HTML: Displays command output in a new browser tab or window
|
8
|
+
# - Show as Popup: Displays command output in a text popup under the cursor in the current document
|
9
|
+
# - Show as HTML Popup: Displays command output in a popup under the cursor in the current document using HTML markup
|
10
|
+
# - Open as URL: Opens the command output as a URL in a new browser tab or window
|
11
|
+
class ShowText < OutputFormat
|
12
|
+
supported_types "Show as HTML", "Show as Popup", "Show as HTML Popup", "Open as URL" #, "Show as Tooltip"
|
13
|
+
|
14
|
+
def format text, type
|
15
|
+
name = "Command Output"
|
16
|
+
case type
|
17
|
+
when "Show as HTML"
|
18
|
+
output = java.io.File.create_temp_file("output","html")
|
19
|
+
output.delete_on_exit
|
20
|
+
path = output.get_absolute_path
|
21
|
+
File.open(path,'w') {|f| f.puts(text)}
|
22
|
+
url = File.expand_path(path)
|
23
|
+
Redcar::HtmlView::DisplayWebContent.new(name,url,false).run
|
24
|
+
when "Open as URL"
|
25
|
+
Redcar::HtmlView::DisplayWebContent.new(name,text.strip,false).run
|
26
|
+
when "Show as HTML Popup"
|
27
|
+
if edit_tab_focussed?
|
28
|
+
Redcar::Application::Dialog.popup_html(text,:below_cursor)
|
29
|
+
else
|
30
|
+
missing_edit_tab type
|
31
|
+
end
|
32
|
+
when "Show as Popup"
|
33
|
+
if edit_tab_focussed?
|
34
|
+
Redcar::Application::Dialog.popup_text(name,text,:below_cursor)
|
35
|
+
else
|
36
|
+
missing_edit_tab type
|
37
|
+
end
|
38
|
+
when "Show as Tooltip"
|
39
|
+
Redcar::Application::Dialog.tool_tip(text,:cursor)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class FilterCommand
|
4
|
+
# Plugin storage manager for FilterCommand
|
5
|
+
class History
|
6
|
+
|
7
|
+
# How many recent commands to save
|
8
|
+
STORAGE_SIZE = 30
|
9
|
+
|
10
|
+
# The last or default used output format
|
11
|
+
# @return [String]
|
12
|
+
def self.output_type
|
13
|
+
@output_type ||= "Replace Selection"
|
14
|
+
end
|
15
|
+
|
16
|
+
# The last or default used input format
|
17
|
+
# @return [String]
|
18
|
+
def self.input_type
|
19
|
+
@input_type ||= "Selection"
|
20
|
+
end
|
21
|
+
|
22
|
+
# The most recently run command
|
23
|
+
# @return [String]
|
24
|
+
def self.command
|
25
|
+
@command ||= ""
|
26
|
+
end
|
27
|
+
|
28
|
+
# The commands and formats stored in history
|
29
|
+
# @return [Hash]
|
30
|
+
def self.recent_commands
|
31
|
+
FilterCommand.storage['recent_commands']
|
32
|
+
end
|
33
|
+
|
34
|
+
# The commands stored in history
|
35
|
+
# @return [Array] list of commands
|
36
|
+
def self.command_list
|
37
|
+
items = []
|
38
|
+
recent_commands.each {|map| items << map['command'] }
|
39
|
+
items
|
40
|
+
end
|
41
|
+
|
42
|
+
# Clears all saved commands
|
43
|
+
def self.clear
|
44
|
+
FilterCommand.storage['recent_commands'] = []
|
45
|
+
end
|
46
|
+
|
47
|
+
# Prepends a command and formats into recent history
|
48
|
+
# @param [String] command the command
|
49
|
+
# @param [String] input_type which input format was used
|
50
|
+
# @param [String] output_type which output format was used
|
51
|
+
def self.update_commands command, input_type, output_type
|
52
|
+
@command, @input_type, @output_type = command, input_type, output_type
|
53
|
+
commands = FilterCommand.storage['recent_commands']
|
54
|
+
commands.reject! {|item| item['command'] == @command}
|
55
|
+
commands.unshift({"command" => @command,"input_type" => @input_type, "output_type" => @output_type })
|
56
|
+
commands = commands[0..STORAGE_SIZE]
|
57
|
+
FilterCommand.storage['recent_commands'] = commands
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class FilterCommand
|
4
|
+
# A means of displaying text. New output formats can be defined by
|
5
|
+
# extending OutputFormat and implementing the `type` and
|
6
|
+
# `format` methods
|
7
|
+
class OutputFormat
|
8
|
+
# A Hash of all known formats
|
9
|
+
def self.formats
|
10
|
+
@types ||= {}
|
11
|
+
end
|
12
|
+
|
13
|
+
# The generator method for `formats`
|
14
|
+
def self.supported_types(*names)
|
15
|
+
if names.any?
|
16
|
+
names.each {|n| OutputFormat.formats[n] = self }
|
17
|
+
@supported_types = supported_types + names
|
18
|
+
else
|
19
|
+
@supported_types ||= []
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# A check whether an editable tab is currently focussed in Redcar
|
24
|
+
def edit_tab_focussed?
|
25
|
+
tab and tab.is_a?(Redcar::EditTab)
|
26
|
+
end
|
27
|
+
|
28
|
+
# The currently focussed tab
|
29
|
+
def tab
|
30
|
+
win = Redcar.app.focussed_window
|
31
|
+
win.focussed_notebook_tab
|
32
|
+
end
|
33
|
+
|
34
|
+
# A newline character (platform-specific)
|
35
|
+
def newline
|
36
|
+
if Redcar.platform == :win
|
37
|
+
newline = "\r\n"
|
38
|
+
else
|
39
|
+
newline = "\n"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# The error message indicating that the currently selected output format
|
44
|
+
# requires the current tab to be an editable tab
|
45
|
+
def missing_edit_tab type
|
46
|
+
Redcar::Application::Dialog.message_box("To use the #{type} output format, the current tab must be an edit tab.")
|
47
|
+
end
|
48
|
+
|
49
|
+
# A name or list of names of supported output formats for the current class
|
50
|
+
def type
|
51
|
+
raise "A name has not been defined by #{self.class.name}. This text is displayed in the Filter Command speedbar."
|
52
|
+
end
|
53
|
+
|
54
|
+
# Where the work happens! This method is called when there is text to be processed
|
55
|
+
# @param [String] text the text to be formatted
|
56
|
+
# @param [String] type a name of a defined output type for the current class
|
57
|
+
def format text, type
|
58
|
+
raise "A format method has not been defined by #{self.class.name}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
require 'java'
|
3
|
+
require 'filter_command/autocompletion'
|
4
|
+
require 'filter_command/commands'
|
5
|
+
require 'filter_command/command_parser'
|
6
|
+
require 'filter_command/evaluator'
|
7
|
+
require 'filter_command/filter_speedbar'
|
8
|
+
require 'filter_command/history'
|
9
|
+
require 'filter_command/output_format'
|
10
|
+
require 'filter_command/formats/discard'
|
11
|
+
require 'filter_command/formats/insert'
|
12
|
+
require 'filter_command/formats/replace'
|
13
|
+
require 'filter_command/formats/show'
|
14
|
+
|
15
|
+
module Redcar
|
16
|
+
# A Shell Command Runner and Parser with support for many output formats
|
17
|
+
class FilterCommand
|
18
|
+
|
19
|
+
# Defined Menu Items to display in Redcar
|
20
|
+
def self.menus
|
21
|
+
Menu::Builder.build do
|
22
|
+
sub_menu "Plugins" do
|
23
|
+
sub_menu "Filter Through Command" do
|
24
|
+
item "Open Speedbar...", FilterCommand::OpenFilterSpeedbar
|
25
|
+
item "Re-run Last Filter", FilterCommand::RerunLastFilter
|
26
|
+
item "Evaluate Text", FilterCommand::EvaluateText
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Registered Default Keybindings
|
33
|
+
def self.keymaps
|
34
|
+
osx = Redcar::Keymap.build("main", :osx) do
|
35
|
+
link "Cmd+Shift+R", OpenFilterSpeedbar
|
36
|
+
link "Ctrl+L", RerunLastFilter
|
37
|
+
link "Ctrl+R", EvaluateText
|
38
|
+
end
|
39
|
+
linwin = Redcar::Keymap.build("main", [:linux, :windows]) do
|
40
|
+
link "Alt+O", OpenFilterSpeedbar
|
41
|
+
link "Alt+U", RerunLastFilter
|
42
|
+
link "Alt+R", EvaluateText
|
43
|
+
end
|
44
|
+
[osx, linwin]
|
45
|
+
end
|
46
|
+
|
47
|
+
# Plugin Storage for recently run commands
|
48
|
+
def self.storage
|
49
|
+
@storage ||= begin
|
50
|
+
storage = Plugin::Storage.new('filter_through_command')
|
51
|
+
storage.set_default('recent_commands', [])
|
52
|
+
storage
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/license
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
LICENSE
|
2
|
+
|
3
|
+
Copyright (c) 2011 Delisa Mason
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/plugin.rb
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redcar-filter-through-command
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.3.0
|
6
|
+
platform: java
|
7
|
+
authors:
|
8
|
+
- Delisa Mason
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-01 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: redcar-dev
|
17
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.12.16dev
|
23
|
+
requirement: *id001
|
24
|
+
prerelease: false
|
25
|
+
type: :runtime
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: cucumber
|
28
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
requirement: *id002
|
35
|
+
prerelease: false
|
36
|
+
type: :development
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
requirement: *id003
|
46
|
+
prerelease: false
|
47
|
+
type: :development
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rcov
|
50
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
requirement: *id004
|
57
|
+
prerelease: false
|
58
|
+
type: :development
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: yard
|
61
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
requirement: *id005
|
68
|
+
prerelease: false
|
69
|
+
type: :development
|
70
|
+
description: Filter Through Command - A Redcar Editor plugin which supports running the current line of a document as a shell script, as well as manipulating and displaying text using shell commands with several options for input and output.
|
71
|
+
email: iskanamagus@gmail.com
|
72
|
+
executables: []
|
73
|
+
|
74
|
+
extensions: []
|
75
|
+
|
76
|
+
extra_rdoc_files: []
|
77
|
+
|
78
|
+
files:
|
79
|
+
- lib/filter_command.rb
|
80
|
+
- lib/filter_command/history.rb
|
81
|
+
- lib/filter_command/evaluator.rb
|
82
|
+
- lib/filter_command/autocompletion.rb
|
83
|
+
- lib/filter_command/output_format.rb
|
84
|
+
- lib/filter_command/filter_speedbar.rb
|
85
|
+
- lib/filter_command/commands.rb
|
86
|
+
- lib/filter_command/command_parser.rb
|
87
|
+
- lib/filter_command/formats/show.rb
|
88
|
+
- lib/filter_command/formats/replace.rb
|
89
|
+
- lib/filter_command/formats/discard.rb
|
90
|
+
- lib/filter_command/formats/insert.rb
|
91
|
+
- license
|
92
|
+
- README.md
|
93
|
+
- changes.md
|
94
|
+
- plugin.rb
|
95
|
+
homepage: http://github.com/kattrali/redcar-filter-through-command
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 2
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 2
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
requirements: []
|
122
|
+
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.8.10
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: Redcar Editor plugin for manipulating text using shell commands
|
128
|
+
test_files: []
|
129
|
+
|