Permalink
Browse files

add command history support

  • Loading branch information...
1 parent 087ee4d commit ba31725167cafffc2815e03351ead2e130b323a8 @defunkt defunkt committed Dec 19, 2009
Showing with 65 additions and 1 deletion.
  1. +13 −1 bin/repl
  2. +16 −0 man/repl.1
  3. +18 −0 man/repl.1.html
  4. +18 −0 man/repl.1.ron
View
@@ -49,9 +49,20 @@ if File.exists?(cdir = File.expand_path(completion_dir))
end
end
+history_dir = ENV['REPL_HISTORY_DIR'] || "~/"
+if File.exists?(hdir = File.expand_path(history_dir))
+ if script = ARGV.detect { |a| a !~ /^-/ }
+ hfile = "#{hdir}/.#{script}_history"
+ end
+end
+
if !ENV['__REPL_WRAPPED'] && system("which rlwrap > /dev/null")
ENV['__REPL_WRAPPED'] = '0'
- rlargs = "-f #{cfile}" if cfile
+
+ rlargs = ""
+ rlargs << " -f #{cfile}" if cfile
+ rlargs << " -H #{hfile}" if hfile
+
exec "rlwrap #{rlargs} #$0 #{ARGV.join(' ')}"
end
@@ -65,6 +76,7 @@ show_help if command.empty?
if debug
print 'rlwrap ' if ENV['__REPL_WRAPPED']
print "-f #{cfile} " if cfile
+ print "-H #{hfile} " if hfile
puts command.inspect
end
View
@@ -130,6 +130,19 @@ the \fBrepl redis\-cli\fR prompt.
The directory searched for completion files can be configured using
the \fBREPL_COMPLETION_DIR\fR environment variable.
.
+.SH "COMMAND HISTORY"
+Because \fBrlwrap\fR supports command history, \fBrepl\fR does too. Any file in \fB~/\fR matching the name of the command you start \fBrepl\fR with prefix
+with a dot and suffixed with "_history" will be used for completion.
+.
+.P
+For instance, a file named \fB~/.redis\-cli_history\fR containing a newline
+separated list of "get set info" will cause "get", "set", and "info"
+to be reachable using the up arrow as command history at the \fBrepl
+redis\-cli\fR prompt.
+.
+.P
+The directory searched for history files can be configured using the\fBREPL_HISTORY_DIR\fR environment variable.
+.
.SH "ENVIRONMENT"
.
.SS "REPL_PROMPT"
@@ -138,6 +151,9 @@ the prompt to display before each line of input. defaults to >>
.SS "REPL_COMPLETION_DIR"
directory in which completion files are kept
.
+.SS "REPL_HISTORY_DIR"
+directory in which command history files are kept
+.
.SH "BUGS"
\fIhttp://github.com/defunkt/repl/issues\fR
.
View
@@ -168,6 +168,20 @@ <h2 id='NAME'>NAME</h2>
<p>The directory searched for completion files can be configured using
the <code>REPL_COMPLETION_DIR</code> environment variable.</p>
+<h2>COMMAND HISTORY</h2>
+
+<p>Because <code>rlwrap</code> supports command history, <code>repl</code> does too. Any file in
+<code>~/</code> matching the name of the command you start <code>repl</code> with prefix
+with a dot and suffixed with "_history" will be used for completion.</p>
+
+<p>For instance, a file named <code>~/.redis-cli_history</code> containing a newline
+separated list of "get set info" will cause "get", "set", and "info"
+to be reachable using the up arrow as command history at the <code>repl
+redis-cli</code> prompt.</p>
+
+<p>The directory searched for history files can be configured using the
+<code>REPL_HISTORY_DIR</code> environment variable.</p>
+
<h2>ENVIRONMENT</h2>
<h3>REPL_PROMPT</h3>
@@ -178,6 +192,10 @@ <h2 id='NAME'>NAME</h2>
<p>directory in which completion files are kept</p>
+<h3>REPL_HISTORY_DIR</h3>
+
+<p>directory in which command history files are kept</p>
+
<h2>BUGS</h2>
<p><a href="http://github.com/defunkt/repl/issues">http://github.com/defunkt/repl/issues</a></p>
View
@@ -101,6 +101,20 @@ the `repl redis-cli` prompt.
The directory searched for completion files can be configured using
the `REPL_COMPLETION_DIR` environment variable.
+## COMMAND HISTORY
+
+Because `rlwrap` supports command history, `repl` does too. Any file in
+`~/` matching the name of the command you start `repl` with prefix
+with a dot and suffixed with "_history" will be used for completion.
+
+For instance, a file named `~/.redis-cli_history` containing a newline
+separated list of "get set info" will cause "get", "set", and "info"
+to be reachable using the up arrow as command history at the `repl
+redis-cli` prompt.
+
+The directory searched for history files can be configured using the
+`REPL_HISTORY_DIR` environment variable.
+
## ENVIRONMENT
### REPL_PROMPT
@@ -111,6 +125,10 @@ the prompt to display before each line of input. defaults to >>
directory in which completion files are kept
+### REPL_HISTORY_DIR
+
+directory in which command history files are kept
+
## BUGS
<http://github.com/defunkt/repl/issues>

0 comments on commit ba31725

Please sign in to comment.