]> arthur.barton.de Git - atom-ax-pipe.git/blobdiff - lib/pipe.coffee
Forgot to put path in quotes.
[atom-ax-pipe.git] / lib / pipe.coffee
index 7a3b9658495fbd3394c2d62cff31bfbd28027dd4..94b5627eb539661bac953ed1fbd42e047d924488 100644 (file)
@@ -2,6 +2,8 @@
 {spawn} = require 'child_process'
 CommandView = require './command-view'
 
+history = []
+
 module.exports =
   activate: ->
     atom.workspaceView.command 'pipe:run', => @run()
@@ -11,15 +13,20 @@ module.exports =
     view = atom.workspaceView.getActiveView()
     return if not editor?
 
-    new CommandView (commandString) ->
+    new CommandView history, (commandString) ->
       if not commandString
         view.focus()
         return
 
+      history.push commandString
+      if history.length > 300
+        history.shift()
+
       range = editor.getSelectedBufferRange()
       stdout = ''
       stderr = ''
 
+      commandString = "cd '#{atom.project.path}' && #{commandString}"
       proc = spawn process.env.SHELL, ["-l", "-c", commandString]
 
       proc.stdout.on 'data', (text) ->
@@ -29,13 +36,7 @@ module.exports =
         stderr += text
 
       proc.on 'close', (code) ->
-        text = stderr || stdout
-        if not text then return
-
-        if text.slice(-1) is '\n'
-          text = text.slice(0, -1)
-
-        editor.setTextInBufferRange(range, text)
+        editor.setTextInBufferRange(range, stderr || stdout)
         editor.setSelectedBufferRange(new Range(range.start, range.start))
         view.focus()