Last active
August 6, 2017 15:01
-
-
Save shunchu/f737a924ffe18a38cfbe to your computer and use it in GitHub Desktop.
chruby hack for chefdk
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
chefdk |
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
unset RUBY_AUTO_VERSION | |
## Added chefdk function | |
function chefdk() { | |
eval "$(chef shell-init bash)" | |
} | |
function chruby_auto() { | |
local dir="$PWD" version | |
until [[ -z "$dir" ]]; do | |
if { read -r version <"$dir/.ruby-version"; } 2>/dev/null || [[ -n "$version" ]]; then | |
if [[ "$version" == "$RUBY_AUTO_VERSION" ]]; then return | |
else | |
RUBY_AUTO_VERSION="$version" | |
## Edited the following code | |
## Begin change ===================== | |
if [[ "$version" == "chefdk" ]]; then | |
chefdk | |
else | |
## End change ======================= | |
chruby "$version" | |
fi | |
return $? | |
fi | |
fi | |
dir="${dir%/*}" | |
done | |
if [[ -n "$RUBY_AUTO_VERSION" ]]; then | |
chruby_reset | |
unset RUBY_AUTO_VERSION | |
fi | |
} | |
if [[ -n "$ZSH_VERSION" ]]; then | |
if [[ ! "$preexec_functions" == *chruby_auto* ]]; then | |
preexec_functions+=("chruby_auto") | |
fi | |
elif [[ -n "$BASH_VERSION" ]]; then | |
trap '[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto' DEBUG | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment