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 commandString = "cd #{atom.project.path} && #{commandString}"
30 proc = spawn process.env.SHELL, ["-l", "-c", commandString]
32 proc.stdout.on 'data', (text) ->
35 proc.stderr.on 'data', (text) ->
38 proc.on 'close', (code) ->
39 editor.setTextInBufferRange(range, stderr || stdout)
40 editor.setSelectedBufferRange(new Range(range.start, range.start))
43 proc.stdin.write(editor.getSelectedText())