You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\fBrepl\fR wraps a non\-interactive \fBcommand\fR in an interactive read\-eval\-print\-loop prompt\. Each line you type into the prompt is executed as arguments to \fBcommand\fR\. Anything written to standard output or standard error by the \fBcommand\fR is displayed\.
.P
If you have \fBrlwrap(1)\fR installed you'll automatically get the full benefits of readline: history, reverse searches, etc\.
.P
\fBrepl\fR is meant to wrap programs which accept command line arguments and print to the standard output\. It keeps no state between executed lines and, as such, cannot be used to replace \fBirb\fR or the Python REPL (for example)\.
.SH "EXAMPLES"
Using \fBrepl\fR with \fBredis\-cli\fR:
.IP""4
.nf
$ repl redis\-cli
>> set name chris
OK
>> get name
chris
>> info
redis_version:1\.000
uptime_in_seconds:182991
uptime_in_days:2
\&\.\. etc \.\.
.fi
.IP""0
.P
Using \fBrepl\fR with Ruby's \fBgem\fR:
.IP""4
.nf
$ repl gem
>> \-\-version
1\.3\.5
>> search yajl
*** LOCAL GEMS ***
yajl\-ruby (0\.6\.7)
>> search yajl \-r
*** REMOTE GEMS ***
brianmario\-yajl\-ruby (0\.6\.3)
filipegiusti\-yajl\-ruby (0\.6\.4)
jdg\-yajl\-ruby (0\.5\.12)
oortle\-yajl\-ruby (0\.5\.8)
yajl\-ruby (0\.6\.7)
.fi
.IP""0
.P
Using \fBrepl\fR with \fBgit\fR:
.IP""4
.nf
$ repl git
>> branch
gh\-pages
* master
>> tag
rm
v0\.1\.0
v0\.1\.1
v0\.1\.2
v0\.1\.3
>> tag \-d rm
Deleted tag 'rm'
>> pwd
git: 'pwd' is not a git\-command\. See 'git \-\-help'\.
Did you mean this?
add
.fi
.IP""0
.SH "OPTIONS"
.TP
\fB\-h\fR, \fB\-\-help\fR
Displays usage information\.
.TP
\fB\-\-stdin\fR
Pipe input to command's STDIN\.
.TP
\fB\-\-debug\fR
Displays debug information while running\.
.TP
\fB\-\-man\fR
Displays this man page\.
.SH "COMPLETION"
Because \fBrlwrap\fR supports completion, \fBrepl\fR does too\. Any file in \fB~/\.repl\fR matching the name of the command you start \fBrepl\fR with will be used for completion\.
.P
For instance, a file named \fB~/\.repl/redis\-cli\fR containing "get set info" will cause "get", "set", and "info" to be tab completeable at the \fBreplredis\-cli\fR prompt\.
.P
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 \fBreplredis\-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"
the prompt to display before each line of input (defaults to \fB>>\fR)
.SS "REPL_ESCAPE"
"shell escape" input lines before invoking command
.SS "REPL_DEBUG"
print out the expanded command before executing it
.SS "REPL_CLEAR"
clear the TTY console before running each command
.SS "REPL_HISTORY_DIR"
directory in which command history files are kept
.SS "REPL_COMPLETION_DIR"
directory in which command completion files are kept
.SH "HOMEPAGE"
\fIhttp://github\.com/pvdb/repl\fR
.P
You will find many more practical examples there!
.SH "BUGS"
\fIhttp://github\.com/pvdb/repl/issues\fR
.SH "AUTHOR"
Peter Vandenberk :: @pvdb \fIhttps://github\.com/pvdb\fR
.SH "CREDITS"
Chris Wanstrath :: @defunkt \fIhttps://github\.com/defunkt\fR
.P
Check out his (awesome, but unmaintained) original version \fIhttps://github\.com/defunkt/repl\fR on which this one is based!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repl wraps a non-interactive command in an interactive
read-eval-print-loop prompt. Each line you type into the prompt is
executed as arguments to command. Anything written to standard
output or standard error by the command is displayed.
If you have rlwrap(1) installed you'll automatically get the full
benefits of readline: history, reverse searches, etc.
repl is meant to wrap programs which accept command line arguments
and print to the standard output. It keeps no state between executed
lines and, as such, cannot be used to replace irb or the Python
REPL (for example).
EXAMPLES
Using repl with redis-cli:
$ repl redis-cli
>> set name chris
OK
>> get name
chris
>> info
redis_version:1.000
uptime_in_seconds:182991
uptime_in_days:2
..etc..
$ repl git
>> branch
gh-pages
* master
>> tag
rm
v0.1.0
v0.1.1
v0.1.2
v0.1.3
>> tag -d rm
Deleted tag 'rm'
>> pwd
git: 'pwd' is not a git-command. See 'git --help'.
Did you mean this?
add
OPTIONS
-h, --help:
Displays usage information.
--stdin:
Pipe input to command's STDIN.
--debug:
Displays debug information while running.
--man:
Displays this man page.
COMPLETION
Because rlwrap supports completion, repl does too. Any file in
~/.repl matching the name of the command you start repl with will
be used for completion.
For instance, a file named ~/.repl/redis-cli containing "get set
info" will cause "get", "set", and "info" to be tab completeable at
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
the prompt to display before each line of input (defaults to >>)
REPL_ESCAPE
"shell escape" input lines before invoking command
REPL_DEBUG
print out the expanded command before executing it
REPL_CLEAR
clear the TTY console before running each command
REPL_HISTORY_DIR
directory in which command history files are kept
REPL_COMPLETION_DIR
directory in which command completion files are kept
repl wraps a non-interactive command in an interactive REPL (read-eval-print loop).
Synopsis
repl [options] command <...>
command is executed using the lines you type into repl's prompt as either command-line arguments or else as standard input, and anything written by command to standard output and standard error is displayed.
This is repeated until you exit out of repl's interactive loop by using either CTRL-C or CTRL-D at the prompt (default is >> ):
$ repl host -t A
>> google.com
google.com has address 216.58.212.206
>> google.co.uk
google.co.uk has address 172.217.169.35
>> ^D
$ _
Usage
repl is meant to wrap programs which accept and process command line arguments or which read from and process standard input, and which in turn print to standard output or standard error, but which don't have an interactive REPL of their own.
If you have rlwrap(1) installed you'll automatically get the full benefits of readline: persistent history, reverse history searches, command-specific tab completions, rich command-line editing, etc.
Combined with rlwrap, repl can provide a much richer interactive environment even when wrapping commands that have their own basic one, by supporting readline features the command itself doesn't.
Limitation
repl keeps no state between subsequent command invocations and, as such, cannot be used to replace things like the Ruby and Python REPLs (irb, pry, etc.), or other language shells.
repl is easily installed as a standalone script somewhere in your ${PATH}; the default install location is /usr/local/bin, but it can be anything on your ${PATH}.
Run the following commands in your preferred shell:
This way you can run repl without any changes to your system's $PATH. Depending on your file system permissions, you may have to use sudo curl instead of just curl.
Examples
In order to show what's going on, the following examples use the --debug option, which makes repl print the expanded command line - prefixed with $ - just before executing in.
basic
By default, anything you enter on repl's prompt is passed on to the command as positional command line arguments:
$ repl --debug git
>> version
$ git version
git version 2.28.0
>> status
$ git status
fatal: not a git repository (or any of the parent directories): .git
>> ^D
$ _
You can also enter multiple command line arguments at once:
$ repl --debug file /etc/%s /etc/%s_Apple_Terminal
>> bashrc
$ file /etc/bashrc /etc/bashrc_Apple_Terminal
/etc/bashrc: ASCII text
/etc/bashrc_Apple_Terminal: ASCII text
>> zshrc
$ file /etc/zshrc /etc/zshrc_Apple_Terminal
/etc/zshrc: ASCII text
/etc/zshrc_Apple_Terminal: ASCII text
>> ^D
$ _
standard input
Using the --stdin option tells repl to write what you enter on the prompt to the command's standard input (instead of providing it as command arguments):
Use the --printf option (in addition to --stdin) to make repl use printf(1) instead of echo(1), thus suppressing newline characters if and when these are superfluous:
--debug - now works correctly in conjunction with --stdin
example: repl --stdin --debug wc -c using defunkt/repl doesn't work
rlwrap improvements
explicitly ignore options/flags for calculating history and completion files
use MakeMakefile.find_executable0() instead of which(1) to find rlwrap
set __REPL_RLWRAP__ to the PID of the parent repl process, instead of 0
command processing
all prompts, debug and error messages are written to IO.console (not STDOUT) for pipelining purposes
example: repl --debug echo > blegga; cat blegga
support for multiple embedded %s placeholders in the command string, not just one
example: repl diff source_dir/%s target_dir/%s
Configuration
The following environment variables can be used to override repl's defaults:
REPL_PROMPT: prompt to use in repl's read-eval-print loop (default: >>)
REPL_ESCAPE: equivalent to the --escape option if set to true (default: false)
REPL_DEBUG : equivalent to the --debug option if set to true (default: false)
REPL_CLEAR : equivalent to the --clear option if set to true (default: false)
REPL_QUIET : equivalent to the --quiet option if set to true (default: false)
REPL_HISTORY_DIR: directory in which history files are kept (default: ${HOME})
REPL_COMPLETION_DIR: directory in which completion files are kept (default: ${HOME}/.repl)
These options can also be set permantently in ${HOME}/.repl.rc, instead of "polluting" your shell environment with them; use the repl.rc template file as a starting point.
TODO
Potential improvements to this new version:
add README.md instructions for "Standalone Installation"
update and improve the usage instructions and examples
update and improve the man page, incl. rake support