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.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 ranges = editor.getSelectedBufferRanges()
31 editor.commitTransaction()
36 editor.beginTransaction()
37 for range, i in ranges
38 marker = editor.markBufferRange range, properties
39 processRange marker, editor, commandString, wg
41 processRange = (marker, editor, commandString, wg) ->
45 proc = spawn process.env.SHELL, ["-l", "-c", commandString]
47 proc.stdout.on 'data', (text) ->
50 proc.stderr.on 'data', (text) ->
53 proc.on 'close', (code) ->
54 text = stderr || stdout
55 editor.setTextInBufferRange(marker.getBufferRange(), text)
58 proc.stdin.write(editor.getTextInBufferRange(marker.getBufferRange()))