Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MAN=$$(head -1 /etc/manpaths)

install:
cp bin/repl /usr/bin/repl
cp man/repl.1 $(MAN)/man1/

uninstall:
rm /usr/bin/repl
rm $(MAN)/man1/repl.1
73 changes: 39 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
repl(1) -- sometimes you need a repl
====================================
REPL
====

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

For example:

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


Or:

$ repl gem
>> --version
gem>> --version
1.3.5
>> search yajl
gem>> search yajl

*** LOCAL GEMS ***

yajl-ruby (0.6.7)
>> search yajl -r
gem>> search yajl -r

*** REMOTE GEMS ***

Expand All @@ -38,22 +36,21 @@ Or:
oortle-yajl-ruby (0.5.8)
yajl-ruby (0.6.7)


Or even:

$ repl git
>> branch
git>> branch
gh-pages
* master
>> tag
git>> tag
rm
v0.1.0
v0.1.1
v0.1.2
v0.1.3
>> tag -d rm
git>> tag -d rm
Deleted tag 'rm'
>> pwd
git>> pwd
git: 'pwd' is not a git-command. See 'git --help'.

Did you mean this?
Expand All @@ -62,7 +59,7 @@ Or even:
You can also use `%s` to tell repl where to stick the input:

$ repl heroku %s --app domainy
>> info
heroku>> info
=== domainy
Web URL: http://domainy.heroku.com/
Git Repo: git@heroku.com:domainy.git
Expand All @@ -74,36 +71,45 @@ You can also use `%s` to tell repl where to stick the input:
Addons: Piggyback SSL
Owner: b****@*******.com


If you have [rlwrap(1)][0] installed you'll automatically get the full
If you have [rlwrap][0] 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
### Rubygems

`repl` can be installed as a gem:

`repl` is easily installed as a standalone script:
```sh
gem install repl
```

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

Change `$REPL_BIN` to your desired location and have at! (Just make
sure it's in your `$PATH`.)
Download this repo, and then just `make` your installation:

### RubyGems
```sh
cd repl-master
sudo make
```

`repl` can also be installed as a RubyGem:
To uninstall, use `sudo make uninstall`.

$ gem install repl
### Curl

You can install REPL without downloading the whole repo. This way:

```sh
curl -s https://raw.github.com/defunkt/repl/master/bin/repl > /usr/bin/repl
curl -s https://raw.github.com/defunkt/repl/master/man/repl.1 > /usr/local/share/man/man1/repl.1
chmod +x /usr/bin/repl
```

Completion
----------
Expand All @@ -129,11 +135,13 @@ Configuration
The following environment variables affect `repl`'s behavior:

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

`REPL_COMPLETION_DIR`:
directory in which completion files are kept

`REPL_HISTORY_DIR`:
directory in which command history files are kept

Contributing
------------
Expand All @@ -146,22 +154,19 @@ Once you've made your great commits:
4. Create an [Issue][2] with a link to your branch
5. That's it!


Meta
----

* Code: `git clone git://github.com/defunkt/repl.git`
* Home: <https://github.com/defunkt/repl>
* Bugs: <https://github.com/defunkt/repl/issues>
* Gems: <http://gemcutter.org/gems/repl>

* Gems: <http://rubygems.org/gems/repl>

Author
------

Chris Wanstrath :: chris@ozmm.org :: @defunkt


[0]: http://utopia.knoware.nl/~hlub/rlwrap/
[1]: http://help.github.com/forking/
[2]: https://github.com/defunkt/repl/issues
44 changes: 20 additions & 24 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
$LOAD_PATH.unshift 'lib'
require "repl/version"

def version
Repl::VERSION
end
Dir.chdir File.dirname(__FILE__)
version = `bin/repl -v`[/\d+\.\d+\.\d+/]

def git(command)
system("git #{command}")
sh "git #{command}"
end

desc "Build manual"
desc 'Build manual'
task :build_man do
sh "ronn -br5 --organization=DEFUNKT man/*.ronn"
sh 'ronn -br5 --organization=DEFUNKT man/*.ronn'
end

desc "Build and show manual"
desc 'Build and show manual'
task :man => :build_man do
exec "man man/repl.1"
exec 'man man/repl.1'
end

desc "Push a new version to Gemcutter"
desc 'Push a new version to Rubygems'
task :publish do
git "tag v#{version}"
git "push origin v#{version}"
git "push origin master"
git "push origin master:latest"
sh "gem build repl.gemspec"
git 'push origin master'
git 'push origin master:latest'
sh 'gem build repl.gemspec'
sh "gem push repl-#{version}.gem"
git "clean -fd"
exec "rake pages"
git 'clean -fd'
exec 'rake pages'
end

desc "Publish to GitHub Pages"
task :pages => [ :build_man ] do
cp "man/repl.1.html", "html"
git "checkout gh-pages"
mv "html", "index.html"
desc 'Publish to GitHub Pages'
task :pages => :build_man do
cp 'man/repl.1.html', 'html'
git 'checkout gh-pages'
mv 'html', 'index.html'
git "commit -a -m 'update docs'"
git "push origin gh-pages"
git "checkout master"
git 'push origin gh-pages'
git 'checkout master'
puts :done
end
125 changes: 35 additions & 90 deletions bin/repl
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,106 +1,51 @@
#!/usr/bin/env ruby
require 'optparse'

# repl(1) -- sometimes you need a repl
#
# repl is an interactive program which tenderly wraps another,
# non-interactive program.
#
# For example:
#
# $ repl redis-cli
# >> set name chris
# OK
# >> get name
# chris
#
# If you have rlwrap(1) installed you'll get the full benefits of
# readline: history, reverse searches, etc.
executable = ARGV.find_index { |a| not a[/^-/] }
man = File.dirname(__FILE__) + '/../man/repl.1'

def show_help
puts <<-help
Usage: repl [options] command ...
options = executable ? ARGV.shift(executable) : ARGV
program = ARGV.join(' ')
settings = {}

Options:
--help Display this message
--stdin Pipe input to command's STDIN
--debug Display each command executed
--man Display the man page
# If nothing but options specified, or nothing
# specified at all, show some help information:
options << %w[-h] unless executable

Bug reports, suggestions, updates:
http://http://github.com/defunkt/repl/issues
help
exit
end

if ARGV.empty? || ARGV.any? { |arg| %w( -h --help -help help ).include?(arg) }
show_help
end
OptionParser.new do |o|
o.banner += ' command'
o.summary_width = 17
o.on('-h', '--help', 'Display this message') { puts o; exit }
o.on('-s', '--stdin', "Pipe input to command's STDIN") { settings[:stdin] = true }
o.on('-d', '--debug', 'Display each command executed') { settings[:debug] = true }
o.on('-m', '--man', 'Display the man page') { exec File.exists?(man) ? "man #{man}" : 'man repl' }
o.on('-v', '--version', 'Print REPL version') { puts 'REPL 1.0.0'; exit }
end.parse(options)

if ARGV.include? '--man'
dir = File.dirname(__FILE__)
exec "man #{dir}/../man/repl.1"
end
name = program.sub('%s', '').gsub(/\W/, '')

completion_dir = ENV['REPL_COMPLETION_DIR'] || "~/.repl"
if File.exists?(cdir = File.expand_path(completion_dir))
script = ARGV.detect { |a| a !~ /^-/ }
if script
cfile = Dir[cdir + '/' + File.basename(script)].first
cfile = nil if cfile && !File.exists?(cfile)
end
end
completion_dir = File.expand_path(ENV['REPL_COMPLETION_DIR'] || '~/.repl')
history_dir = File.expand_path(ENV['REPL_HISTORY_DIR'] || '~')

history_dir = ENV['REPL_HISTORY_DIR'] || "~/"
if File.exists?(hdir = File.expand_path(history_dir))
if script = ARGV.detect { |a| a !~ /^-/ }
script = File.basename(script)
hfile = "#{hdir}/.#{script}_history"
end
end
settings[:completion] = "-f #{completion_dir}/#{name}" if File.exists? completion_dir
settings[:history] = "-H #{history_dir}/.#{name}_history" if File.exists? history_dir

if !ENV['__REPL_WRAPPED'] && system("which rlwrap > /dev/null 2> /dev/null")
if `which rlwrap 1>&2> /dev/null` && !ENV['__REPL_WRAPPED']
ENV['__REPL_WRAPPED'] = '0'

rlargs = ""
rlargs << " -f #{cfile}" if cfile
rlargs << " -H #{hfile}" if hfile

exec "rlwrap #{rlargs} #$0 #{ARGV.join(' ')}"
rlwrap = ['rlwrap', settings[:completion], settings[:history], $0, options.join(' '), program] * ' '
puts rlwrap if settings[:debug]
exec rlwrap
end

if ARGV[0] == '--debug'
debug = ARGV.delete('--debug')
end

if ARGV.include? '--stdin'
from_stdin = ARGV.delete('--stdin')
end
puts settings.to_a.map { |n| n * ': ' } * "\n" << "\nprogram: #{program}" if settings[:debug]

command = ARGV.join(' ')
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
prompt = (ENV['REPL_PROMPT'] || '%s>> ') % ARGV.first
pattern = settings[:stdin] ? "echo \"%s\" | #{program}" : "#{program} %s"

%w[INT TERM].each { |s| trap(s) { abort '' } }
loop do
print ENV['REPL_PROMPT'] || "#{ARGV[0]}>> "

begin
line = $stdin.gets.chomp
rescue NoMethodError, Interrupt
exit
end

if from_stdin
run = "echo \"%s\" | #{command}" % [ line, nil ]
else
run = "#{command} %s" % [ line, nil ]
end
puts "$ #{run}" if debug
system run
warn "Use Ctrl-D (i.e. EOF) to exit" if line =~ /^(exit|quit)$/
print prompt
command = pattern % [STDIN.gets.chomp, nil]
puts "$ #{command}" if settings[:debug]
system command
end
3 changes: 0 additions & 3 deletions lib/repl/version.rb

This file was deleted.

Loading