1 {Range} = require 'atom'
2 {spawn} = require 'child_process'
3 CommandView = require './command-view'
9 atom.commands.add 'atom-workspace', "pipe:run", => @run()
12 editor = atom.workspace.getActiveTextEditor()
15 view = atom.views.getView(atom.workspace)
17 new CommandView history, (commandString) ->
22 history.push commandString
23 if history.length > 300
26 if atom.project.rootDirectory?
27 commandString = "cd '#{atom.project.rootDirectory.path}' && #{commandString}"
28 properties = { reversed: true, invalidate: 'never' }
30 ranges = editor.getSelectedBufferRanges()
32 editor.commitTransaction()
37 editor.beginTransaction()
38 for range, i in ranges
39 marker = editor.markBufferRange range, properties
40 processRange marker, editor, commandString, wg
42 processRange = (marker, editor, commandString, wg) ->
46 proc = spawn process.env.SHELL, ["-l", "-c", commandString]
48 proc.stdout.on 'data', (text) ->
51 proc.stderr.on 'data', (text) ->
54 proc.on 'close', (code) ->
55 text = stderr || stdout
56 editor.setTextInBufferRange(marker.getBufferRange(), text)
59 proc.stdin.write(editor.getTextInBufferRange(marker.getBufferRange()))