-
Notifications
You must be signed in to change notification settings - Fork 313
Quickly fire up a console with 'zip' pre-loaded. #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this would be useful. One suggestion on the implementation.
Another possible implementation (based on https://stackoverflow.com/a/46941281):
#!/usr/bin/env sh
exec irb -I lib -r zip
bin/console
Outdated
lib = File.expand_path(File.join('..', 'lib'), __dir__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'zip' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's possible to do this with require_relative
now (I think since 1.9), without the path manipulation:
require_relative '../lib/zip'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always forget about require_relative
. I'll change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having now tried this, require_relative
doesn't actually work, because everything in lib/zip.rb
is require
d, so also relies on $LOAD_PATH
being set correctly.
So I could fix this, but it would be a lot more involved that just changing this file. Happy to do so if you think it's worth it?
The problem with
you'd need something like |
OK, the current script isn't bad, and I don't want to belabour the point, but to make sure we've gone through the options:
#!/usr/bin/env bash
exec irb -I $(dirname "${BASH_SOURCE[0]}")../lib -r zip |
Sorry, forgot about this one for a while. The other reason I went the ruby (rather than shell) route, is that this mimics the current working of bundler: when you're starting a gem from scratch you can do I've now gone back and looked at how bundler sets this file up and adjusted it accordingly. I think it's pretty neat now, and doesn't rely on shell variables and so on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice 👍 .
I find myself testing things in
irb
enough that this has proved useful, so I decided to commit it.It's purely a developer nicety so isn't stored in the gem.