]> arthur.barton.de Git - atom-ax-pipe.git/commitdiff
Command history
authormoshee <moshee@displaynone.us>
Sun, 16 Mar 2014 04:58:47 +0000 (21:58 -0700)
committermoshee <moshee@displaynone.us>
Sun, 16 Mar 2014 04:58:47 +0000 (21:58 -0700)
lib/command-view.coffee
lib/pipe.coffee
package.json

index dd2eebb6a6fef824445ddf62851fd029ecaaa91e..8ac7c49e34a59c90696baab07540892494e05ced 100644 (file)
@@ -20,13 +20,36 @@ class CommandView extends View
   @samplePlaceholder: ->
     @placeholders[Math.floor(Math.random()*@placeholders.length)]
 
-  initialize: (callback) ->
+  initialize: (history, callback) ->
+    historyPos = history.length
+    cur = ''
+
     @on 'core:cancel core:close', =>
       callback(null)
       @detach()
     @on 'core:confirm', =>
       callback(@commandLine.getText())
       @detach()
+    @commandLine.on 'keydown', (e) =>
+      if history.length is 0 then return
+
+      switch e.keyCode
+        when 38 # up
+          unless historyPos <= 0
+            historyPos--
+            @commandLine.setText history[historyPos]
+
+        when 40 # down
+          if historyPos >= history.length-1
+            historyPos = history.length
+            @commandLine.setText cur
+          else
+            historyPos++
+            @commandLine.setText history[historyPos]
+
+        else
+          if historyPos >= history.length
+            cur = @commandLine.getText()
 
     atom.workspaceView.append(this)
     @commandLine.focus()
index ec25ab594b2d63b307ff4aa46424f9277c7c833d..8db43da6be01e501a02c1809e6682f3a6f9f3b19 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,11 +13,15 @@ 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 = ''
index 58b21ec513e33eafbf47fdeb2b347e9feaa8ff08..db6aa0908076af8df453acc6fcb2751d2f9fc63f 100644 (file)
@@ -6,10 +6,25 @@
   "activationEvents": [
     "pipe:run"
   ],
-  "repository": "https://github.com/moshee/atom-pipe",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/moshee/atom-pipe"
+  },
   "license": "MIT",
   "engines": {
     "atom": ">0.72.0"
   },
-  "dependencies": {}
+  "dependencies": {},
+  "readme": "# pipe\n\nSelect text to pipe into external commands and replace it with the output. Sort\nof like `!` in vim. Commands are sent to your `$SHELL`.\n\nDefault keybinding to activate is `cmd-;`.\n\n![pipe in action](https://i.ktkr.us/hoeJ)\n",
+  "readmeFilename": "README.md",
+  "bugs": {
+    "url": "https://github.com/moshee/atom-pipe/issues"
+  },
+  "homepage": "https://github.com/moshee/atom-pipe",
+  "_id": "pipe@0.1.1",
+  "dist": {
+    "shasum": "065fe0c782ea86980b8cf8e19d2fc40b5851c941"
+  },
+  "_resolved": "/var/folders/hv/nq12s2fx5lv48rtffsd8v2_h0000gn/T/d-114214-49660-1x5dm6u/package.tgz",
+  "_from": "/var/folders/hv/nq12s2fx5lv48rtffsd8v2_h0000gn/T/d-114214-49660-1x5dm6u/package.tgz"
 }