Last active
January 31, 2019 16:15
-
-
Save chrisbloom7/40496e02c711dda35026 to your computer and use it in GitHub Desktop.
Bash shortcuts for routing Rails commands through the binstubs if they are present, or fallback to the other version-dependent methods
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
# RUBY / RUBY ON RAILS COMMANDS | |
alias bexec='bundle exec' | |
alias rails_mv="bexec rails -v | sed 's/Rails \([0-9]\).*/\1/g'" | |
# Alias the rake command to Spring binstubs or fallback to "bundle exec" | |
# http://goo.gl/HkhHAf, http://goo.gl/STtIvF | |
function brake { | |
if [ -f bin/rake ] | |
then | |
bin/rake "$@" | |
else | |
if [ `rails_mv` -lt 3 ]; then | |
rake "$@" | |
else | |
bexec rake "$@" | |
fi | |
fi | |
} | |
function brails { | |
if [ -f bin/rake ] | |
then | |
bin/rails "$@" | |
else | |
bexec rails "$@" | |
fi | |
} | |
function cons { | |
if [ `rails_mv` -lt 3 ]; then | |
./script/console "$@" | |
else | |
brails c "$@" | |
fi | |
} | |
function dbcons { | |
if [ `rails_mv` -lt 3 ]; then | |
echo "Not supported in this version of Rails (`rails -v`)" | |
else | |
brails db "$@" | |
fi | |
} | |
function gen { | |
if [ `rails_mv` -lt 3 ]; then | |
./script/generate "$@" | |
else | |
brails g "$@" | |
fi | |
} | |
function srv { | |
if [ `rails_mv` -lt 3 ]; then | |
./script/server "$@" | |
else | |
brails s "$@" | |
fi | |
} | |
function run { | |
if [ `rails_mv` -lt 3 ]; then | |
./script/runner "$@" | |
else | |
brails r "$@" | |
fi | |
} | |
alias sandbox='cons --sandbox' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I now prefer the bundler plugin for oh-my-zsh.