Skip to content

Instantly share code, notes, and snippets.

@chrisbloom7
Last active January 31, 2019 16:15
Show Gist options
  • Save chrisbloom7/40496e02c711dda35026 to your computer and use it in GitHub Desktop.
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
# 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'
@chrisbloom7
Copy link
Author

chrisbloom7 commented Jan 31, 2019

I now prefer the bundler plugin for oh-my-zsh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment