Last active
July 5, 2021 22:51
-
-
Save infews/20a0d80664d4720a1b3665a557db6343 to your computer and use it in GitHub Desktop.
a "better" be "alias" for bundle exec, prioritizing local binstubs
This file contains hidden or 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
#!/usr/bin/env ruby | |
# Smarter be for ruby projects that prioritizes local project binstubs | |
# - uses zsh when needed, assuming MacOS Catalina or later | |
# - save on your path | |
# - drop the .rb | |
# - chmod +x | |
# - always type `be <command>` and the right thing should happen | |
# | |
# - inspired by Justin Searls (@searls) | |
require "shellwords" | |
class Be | |
def self.execute(command, all_params) | |
if File.exist?("./bin/#{command}") | |
system "bin/#{all_params.join(" ")}" | |
else | |
escaped_command = Shellwords.escape("bundle exec #{all_params.join(" "}") | |
system "zsh -c #{escaped_command}" | |
end | |
end | |
end | |
Be.execute(ARGV[0], ARGV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment