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 if atom.project.rootDirectory?
26 commandString = "cd '#{atom.project.rootDirectory.path}' && #{commandString}"
27 properties = { reversed: true, invalidate: 'never' }
29 for range in editor.getSelectedBufferRanges()
30 marker = editor.markBufferRange range, properties
31 processRange marker, editor, commandString
35 processRange = (marker, editor, commandString) ->
39 proc = spawn process.env.SHELL, ["-l", "-c", commandString]
41 proc.stdout.on 'data', (text) ->
44 proc.stderr.on 'data', (text) ->
47 proc.on 'close', (code) ->
48 text = stderr || stdout
49 editor.setTextInBufferRange(marker.getBufferRange(), text)
51 proc.stdin.write(editor.getTextInBufferRange(marker.getBufferRange()))