1 {Range} = require 'atom'
2 {spawn} = require 'child_process'
3 CommandView = require './command-view'
7 atom.workspaceView.command 'pipe:run', => @run()
10 editor = atom.workspace.getActiveEditor()
11 view = atom.workspaceView.getActiveView()
14 new CommandView (commandString) ->
19 range = editor.getSelectedBufferRange()
23 proc = spawn process.env.SHELL, ["-l", "-c", commandString]
25 proc.stdout.on 'data', (text) ->
28 proc.stderr.on 'data', (text) ->
31 proc.on 'close', (code) ->
32 editor.setTextInBufferRange(range, stderr || stdout)
33 editor.setSelectedBufferRange(new Range(range.start, range.start))
36 proc.stdin.write(editor.getSelectedText())