Skip to content

Instantly share code, notes, and snippets.

@plukevdh
Last active August 29, 2015 14:01
Show Gist options
  • Save plukevdh/ef2778c08106cc7e8c41 to your computer and use it in GitHub Desktop.
Save plukevdh/ef2778c08106cc7e8c41 to your computer and use it in GitHub Desktop.
Shell helpers for sharing setups between dev and prod .rvmrc files
setup_env() {
if [[ -f ".env" ]]; then
for line in `cat .env`; do export $line; done
echo "Loaded .env file from this directory"
fi
}
bundled_commands=(foreman rackup rake rspec ruby shotgun thin pry)
_bundler-installed() {
which bundle > /dev/null 2>&1
}
_within-bundled-project() {
local check_dir=$PWD
while [ $check_dir != "/" ]; do
[ -f "$check_dir/Gemfile" ] && return
check_dir="$(dirname $check_dir)"
done
false
}
_run-with-bundler() {
if _bundler-installed && _within-bundled-project; then
bundle exec $@
else
$@
fi
}
for cmd in $bundled_commands; do
eval "function unbundled_$cmd () { $cmd \$@ }"
eval "function bundled_$cmd () { _run-with-bundler $cmd \$@}"
alias $cmd=bundled_$cmd
if which _$cmd > /dev/null 2>&1; then
compdef _$cmd bundled_$cmd=$cmd
fi
done
setup_env
cd () {
builtin cd "$@"
setup_env
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment