]> arthur.barton.de Git - atom-ax-pipe.git/blobdiff - lib/pipe.coffee
Prepare 0.3.1 release
[atom-ax-pipe.git] / lib / pipe.coffee
index 3a455eea73b5fcfd63a447972e5859077a8db463..5294840bd507d0833bc6a85f296f20a40320056f 100644 (file)
@@ -22,23 +22,31 @@ module.exports =
       if history.length > 300
         history.shift()
 
-      range = editor.getSelectedBufferRange()
-      stdout = ''
-      stderr = ''
+      if atom.project.rootDirectory?
+        commandString = "cd '#{atom.project.rootDirectory.path}' && #{commandString}"
+      properties = { reversed: true, invalidate: 'never' }
 
-      commandString = "cd #{atom.project.path} && #{commandString}"
-      proc = spawn process.env.SHELL, ["-l", "-c", commandString]
+      for range in editor.getSelectedBufferRanges()
+        marker = editor.markBufferRange range, properties
+        processRange marker, editor, commandString
 
-      proc.stdout.on 'data', (text) ->
-        stdout += text
+      view.focus()
 
-      proc.stderr.on 'data', (text) ->
-        stderr += text
+processRange = (marker, editor, commandString) ->
+  stdout = ''
+  stderr = ''
 
-      proc.on 'close', (code) ->
-        editor.setTextInBufferRange(range, stderr || stdout)
-        editor.setSelectedBufferRange(new Range(range.start, range.start))
-        view.focus()
+  proc = spawn process.env.SHELL, ["-l", "-c", commandString]
+
+  proc.stdout.on 'data', (text) ->
+    stdout += text
+
+  proc.stderr.on 'data', (text) ->
+    stderr += text
+
+  proc.on 'close', (code) ->
+    text = stderr || stdout
+    editor.setTextInBufferRange(marker.getBufferRange(), text)
 
-      proc.stdin.write(editor.getSelectedText())
-      proc.stdin.end()
+  proc.stdin.write(editor.getTextInBufferRange(marker.getBufferRange()))
+  proc.stdin.end()