Skip to content

Instantly share code, notes, and snippets.

@slumos
Created September 23, 2012 05:22
Show Gist options
  • Select an option

  • Save slumos/3768957 to your computer and use it in GitHub Desktop.

Select an option

Save slumos/3768957 to your computer and use it in GitHub Desktop.
#! /usr/bin/env zsh
user="$1"
env="$2"
function usage {
cat <<EOF 2>&1
usage: ru rails_user rails_env command args...
Run command as rails_user with RAILS_ENV=rails_env.
Also copies invoking user's PATH into the target env.
e.g. ru wgadmin production rails console
ru integritie production rake unicorn:status
EOF
}
if [[ -z "$user" || -z "$env" ]]; then
usage
exit 1
fi
shift 2
sudo -u "$user" /usr/bin/env "PATH=$PATH" "RAILS_ENV=$env" bundle exec $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment