Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

functional 0.1.0 release

commit 0fcd4e29286ca9ae6078a81a27f31128dea0d743 1 parent 7ca40de
@tmpvar authored
View
1  .gitignore
@@ -0,0 +1 @@
+gmon.out
View
24 README.md
@@ -0,0 +1,24 @@
+# repl.history
+
+Persist a node repl's history to a file.
+
+## from node
+
+install: `npm install repl.history`
+
+```javascript
+var repl = require('repl').start('> ');
+require('repl.history')(repl, process.env.HOME + '/.node_history');
+```
+
+this will drop a `.node_history` file in your home directory.
+
+## from the command line
+
+install: `npm install -g repl.history`
+
+run `repl.history` on the command line
+
+A file `~/.node_history` will be created.
+
+I like to alias it to `nr` for node repl
View
3  bin/repl.history
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+var repl = require('repl').start('> ');
+require('../')(repl, process.env.HOME + '/.node_history');
View
42 index.js
@@ -0,0 +1,42 @@
+var fs = require('fs');
+module.exports = function (repl, file) {
+
+ try {
+ var stat = fs.statSync(file);
+ repl.rli.history = fs.readFileSync(file, 'utf-8').split('\n').reverse();
+ repl.rli.history.shift();
+ repl.rli.historyIndex = 0;
+ } catch (e) {}
+
+ var fd = fs.openSync(file, 'a'), reval = repl.eval;
+
+ repl.eval = function(code, context, file, cb) {
+ var last = code.substring(1)
+ last = last.substring(0, last.length-2);
+
+ if (last && last !== '.history') {
+ fs.write(fd, last + '\n');
+ } else {
+ repl.rli.historyIndex++;
+ repl.rli.history.pop();
+ }
+
+ reval(code, context, file, cb);
+ }
+
+ process.on('exit', function() {
+ fs.closeSync(fd);
+ });
+
+ repl.commands['.history'] = {
+ help : 'Show the history',
+ action : function() {
+ var out = [];
+ repl.rli.history.forEach(function(v, k) {
+ out.push(v);
+ });
+ repl.outputStream.write(out.reverse().join('\n') + '\n');
+ repl.displayPrompt();
+ }
+ };
+};
View
18 package.json
@@ -0,0 +1,18 @@
+{
+ "author": "Elijah Insua <tmpvar@gmail.com> (http://tmpvar.com)",
+ "name": "repl.history",
+ "description": "add history to node's repl",
+ "version": "0.1.0",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com//tmpvar/repl.history"
+ },
+ "engines": {
+ "node": "0.6.x"
+ },
+ "dependencies": {},
+ "devDependencies": {},
+ "bin" : {
+ "repl.history" : "./bin/repl.history"
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.