Coder Social home page Coder Social logo

repl's Introduction

repl(1) -- sometimes you need a repl

repl is an interactive program which tenderly wraps another, non-interactive program.

For example:

$ repl redis-cli -p 6665
>> set name chris
OK
>> get name
chris
>> info
redis_version:1.000
uptime_in_seconds:182991
uptime_in_days:2
.. etc ..

Or:

$ 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)

Or even:

$ 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

You can also use %s to tell repl where to stick the input:

$ repl heroku %s --app domainy
>> info
=== domainy
Web URL:        http://domainy.heroku.com/
Git Repo:       [email protected]:domainy.git
Dynos:          1
Workers:        0
Repo size:      288k
Slug size:      4k
Data size:      0K in 0 table
Addons:         Piggyback SSL
Owner:          b****@*******.com

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).

Install

Standalone

repl is easily installed as a standalone script:

export REPL_BIN=~/bin/repl
curl -s https://raw.github.com/defunkt/repl/latest/bin/repl > $REPL_BIN
chmod 755 $REPL_BIN

Change $REPL_BIN to your desired location and have at! (Just make sure it's in your $PATH.)

RubyGems

repl can also be installed as a RubyGem:

$ gem install repl

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.

See the repl-completion project for a few common, pre-rolled completion files.

Configuration

The following environment variables affect repl's behavior:

REPL_PROMPT: the prompt to display before each line of input. defaults to >>

REPL_COMPLETION_DIR: directory in which completion files are kept

Contributing

Once you've made your great commits:

  1. Fork repl
  2. Create a topic branch - git checkout -b my_branch
  3. Push to your branch - git push origin my_branch
  4. Create an Issue with a link to your branch
  5. That's it!

Meta

Author

Chris Wanstrath :: [email protected] :: @defunkt

repl's People

Contributors

chris123457 avatar citizen428 avatar defunkt avatar grogs avatar jdp avatar jrom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

repl's Issues

ported to POSIX sh

I needed repl on boxes that I'm not able to install Ruby on (for a variety of reasons). So, for greater portability, I ended up porting it to (what I hope is) POSIX compliant sh. In my tests, it was 99% compatible with your original; the only two differences are exiting on ^C instead of on ^D, and the addition of a --version flag.

I don't expect you to do much (anything?) with this, but I didn't know what else to do with it except contribute it back.

https://github.com/joh6nn/repl/tree/POSIX-sh

Pipe line input to command's stdin

Some programs I'd like a REPL for don't take input from the command line, but from standard input. My branch lets you provide the --stdin switch to pipe the line input to the command's standard input. I also fixed the which rlwrap call, it now also pipes standard error to /dev/null. On my machine I was still seeing the which error output when not having rlwrap installed.

EDIT: you can also use repl ./command, before the ./ notation was causing rlwrap to die.

My branch is here: http://github.com/jdp/repl/tree/jdp-stdin

Customizing `REPL_PROMPT`

So, repl checks for a REPL_PROMPT environment variable on startup.

I tried using the environment variable to colorize the prompt, but repl prints the color escape sequences literally. I also can’t use #{ARGV[0]} because it, too, is printed out verbatim.

These two things make customization with REPL_PROMPT pretty useless.

Change prompt to [cmd]>>

repl is awesome. In fact sometimes I'm using it for a couple of different programs.

The thing is, if I open too many at once, or I leave for food and come back to pick up where I left off, I quickly forget and have absolutely no idea which command I’ve repl-ed in which terminal.

It'd be fantastic if repl put the command it’s currently wrapping into the prompt. ☺

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.