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 commandString = "cd '#{atom.project.path}' && #{commandString}"
26 properties = { reversed: true, invalidate: 'never' }
28 for range in editor.getSelectedBufferRanges()
29 marker = editor.markBufferRange range, properties
30 processRange marker, editor, commandString
34 processRange = (marker, editor, commandString) ->
38 proc = spawn process.env.SHELL, ["-l", "-c", commandString]
40 proc.stdout.on 'data', (text) ->
43 proc.stderr.on 'data', (text) ->
46 proc.on 'close', (code) ->
47 text = stderr || stdout
48 editor.setTextInBufferRange(marker.getBufferRange(), text)
50 proc.stdin.write(editor.getTextInBufferRange(marker.getBufferRange()))