Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rcmoret
Created September 15, 2016 22:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcmoret/6d232b708fb2d45be86a8e01e46e17aa to your computer and use it in GitHub Desktop.
Save rcmoret/6d232b708fb2d45be86a8e01e46e17aa to your computer and use it in GitHub Desktop.
Script for opening a rails console for an app within vagrant
#! /bin/bash
if [[ -z $1 ]]; then
APP_NAME=$(basename `pwd`)
else
APP_NAME=$1
fi
echo "Opening Rails Console for $APP_NAME in vagrant..."
cd ~/vagrant && vagrant ssh -c "cd /pub/$APP_NAME/current && bundle exec rails console"
@AlexMooney
Copy link

Add cd - or cd code/$APP_NAME to the end, so that when you log out of vagrant, you end up where you were on the host.

@AlexMooney
Copy link

Also, line 4: pwd | sed 's,.*vagrant/code/\([^/]*\).*,\1,' to make it work even when you're in a sub-directory.

@AlexMooney
Copy link

This should drop you back out if you typo the app_name, rather than leave you sitting in the VM: vagrant ssh -c "cd /pub/$APP_NAME/current || exit; bundle exec rails console"

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