1 {Range} = require 'atom'
2 {spawn} = require 'child_process'
3 CommandView = require './command-view'
9 atom.workspaceView.command 'pipe:run', => @run()
12 editor = atom.workspace.getActiveEditor()
13 view = atom.workspaceView.getActiveView()
16 new CommandView history, (commandString) ->
21 history.push commandString
22 if history.length > 300
25 range = editor.getSelectedBufferRange()
29 proc = spawn process.env.SHELL, ["-l", "-c", commandString]
31 proc.stdout.on 'data', (text) ->
34 proc.stderr.on 'data', (text) ->
37 proc.on 'close', (code) ->
38 editor.setTextInBufferRange(range, stderr || stdout)
39 editor.setSelectedBufferRange(new Range(range.start, range.start))
42 proc.stdin.write(editor.getSelectedText())