Skip to content
This repository
Browse code

docs

  • Loading branch information...
commit f226b4f4b87f30f9822f8df80f44e000ddce4068 1 parent 8e527a4
TJ Holowaychuk authored

Showing 2 changed files with 57 additions and 22 deletions. Show diff stats Hide diff stats

  1. +56 21 Readme.md
  2. +1 1  examples/auto-editor.js
77 Readme.md
Source Rendered
@@ -105,6 +105,38 @@ exports.PS1 = function(){
105 105 > . test
106 106 ```
107 107
  108 +### Aliases
  109 +
  110 +```js
  111 +shell.alias('GET', 'burl GET');
  112 +shell.alias('HEAD', 'burl -I');
  113 +shell.alias('POST', 'burl POST');
  114 +shell.alias('PUT', 'burl PUT');
  115 +shell.alias('PATCH', 'burl PATCH');
  116 +shell.alias('DELETE', 'burl DELETE');
  117 +shell.alias('DEL', 'burl DELETE');
  118 +shell.alias('OPTIONS', 'burl OPTIONS');
  119 +```
  120 +
  121 +## Debugging
  122 +
  123 +```js
  124 +$ DEBUG=nshell ./bin/shell
  125 +> cat Readme.md
  126 + nshell cmd [{"name":"cat","argv":["Readme.md"]}] +1.1m
  127 + nshell env {} +0ms
  128 + nshell which cat +0ms
  129 + nshell found /bin/cat +2ms
  130 + nshell spawn /bin/cat ["Readme.md"] +0ms
  131 + nshell exit 0 +5ms
  132 + nshell prompt +0ms
  133 +```
  134 +
  135 +## Examples
  136 +
  137 + Some cool examples showing off the power
  138 + of scripting your shell!
  139 +
108 140 ### Auto-cd
109 141
110 142 By default `nshell(1)` does not auto-chdir when
@@ -140,31 +172,34 @@ Usage:
140 172 /Users/tj/projects/nshell
141 173 ```
142 174
143   -### Aliases
  175 +### Auto-edit
  176 +
  177 + By default `nshell(1)` will simply give you
  178 + a "command not found" error if you try to
  179 + type a filename, however you can script
  180 + in the ability to edit that file depending
  181 + on its mime type:
144 182
145 183 ```js
146   -shell.alias('GET', 'burl GET');
147   -shell.alias('HEAD', 'burl -I');
148   -shell.alias('POST', 'burl POST');
149   -shell.alias('PUT', 'burl PUT');
150   -shell.alias('PATCH', 'burl PATCH');
151   -shell.alias('DELETE', 'burl DELETE');
152   -shell.alias('DEL', 'burl DELETE');
153   -shell.alias('OPTIONS', 'burl OPTIONS');
154   -```
  184 +// $ npm install mime
155 185
156   -## Debugging
  186 +var path = require('path');
  187 +var mime = require('mime');
157 188
158   -```js
159   -$ DEBUG=nshell ./bin/shell
160   -> cat Readme.md
161   - nshell cmd [{"name":"cat","argv":["Readme.md"]}] +1.1m
162   - nshell env {} +0ms
163   - nshell which cat +0ms
164   - nshell found /bin/cat +2ms
165   - nshell spawn /bin/cat ["Readme.md"] +0ms
166   - nshell exit 0 +5ms
167   - nshell prompt +0ms
  189 +// auto-editor (silly implementation)
  190 +
  191 +shell.on('command', function(e){
  192 + var line = e.line.trim();
  193 + var type = mime.lookup(line);
  194 + switch (type) {
  195 + case 'text/plain':
  196 + case 'text/css':
  197 + case 'application/javascript':
  198 + e.preventDefault();
  199 + shell.exec('mate "' + line + '"');
  200 + break;
  201 + }
  202 +});
168 203 ```
169 204
170 205 ## Todo
2  examples/auto-editor.js
@@ -4,7 +4,7 @@
4 4
5 5 console.log('loaded!');
6 6
7   -// $npm install mime
  7 +// $ npm install mime
8 8
9 9 var path = require('path');
10 10 var mime = require('mime');

0 comments on commit f226b4f

Please sign in to comment.
Something went wrong with that request. Please try again.