Permalink
Browse files

add !! support

  • Loading branch information...
1 parent 4662abd commit 772ba5999a9ce3ccf2415bbfbd12c86a520f4d57 @tj committed Jul 29, 2012
Showing with 12 additions and 20 deletions.
  1. +0 −15 lib/builtins.js
  2. +5 −4 lib/nshell.js
  3. +2 −1 lib/utils.js
  4. +5 −0 test/utils.js
View
@@ -31,21 +31,6 @@ exports['.'] = function(cmd, shell){
return proc;
};
-/**
- * !! [arg ...]
- */
-
-exports['!!'] = function(cmd, shell){
- var proc = new Process;
-
- shell.rl.history.shift();
- var last = shell.rl.history[0];
- last += cmd.argv.join(' ');
- shell.exec(last);
-
- return proc;
-};
-
/**
* cd <path>
*/
View
@@ -233,6 +233,7 @@ Shell.prototype.process = function(cmds){
cmd.argv = cmd.argv.map(function(arg){
switch (arg) {
case '$?': return self.lastExitStatus;
+ case '!!': return self.lastCommand;
default: return utils.unquote(arg);
}
});
@@ -281,12 +282,12 @@ Shell.prototype.cd = function(dir){
Shell.prototype.exec = function(line){
line = line.trim();
- if ('' == line) return this.emit('blank'), this.prompt();
- this.lastCommand = line;
- if (utils.isDirectory(line)) return this.cd(line);
+ if ('' == line) return this.lastCommand = line, this.emit('blank'), this.prompt();
+ if (utils.isDirectory(line)) return this.lastCommand = line, this.cd(line);
var cmds = utils.parse(line);
- if (!cmds.length) return this.prompt();
+ if (!cmds.length) return this.lastCommand = line, this.prompt();
this.process(cmds);
+ this.lastCommand = line;
debug('cmd %j', cmds);
debug('env %j', cmds.env);
if (!this.lookup(cmds)) return this.prompt();
View
@@ -23,7 +23,8 @@ function scan(str) {
var m;
while (m = re.exec(str)) {
tok = m[0];
- tok = braceExpand(tok);
+ // TODO: minimatch bug
+ if ('!!' != tok) tok = braceExpand(tok);
toks = toks.concat(tok);
}
return toks;
View
@@ -36,6 +36,11 @@ describe('utils.parse(str)', function(){
var cmds = utils.parse('foo{bar,baz,raz}');
cmds[0].should.eql({ env: {}, argv: ['foobaz', 'fooraz'], name: 'foobar' });
})
+
+ it('should parse !!', function(){
+ var cmds = utils.parse('echo !!');
+ cmds[0].should.eql({ env: {}, argv: ['!!'], name: 'echo' });
+ })
})
describe('utils.unquote(str)', function(){

0 comments on commit 772ba59

Please sign in to comment.