dotfiles/shell/chruby

28 lines
683 B
Text
Executable file

if [[ -f /opt/arch/share/chruby/chruby.sh ]]; then
source /opt/arch/share/chruby/chruby.sh
fi
_ruby-version() {
local check_dir=$PWD
local next_check_dir=${check_dir%/*}
while [ "$next_check_dir" != "" ]; do
if [[ -f "$check_dir/.ruby-version" ]]; then
cat "$check_dir/.ruby-version"
return
fi
check_dir="$next_check_dir"
next_check_dir=${check_dir%/*}
done
if [[ -f $HOME/.ruby-version ]]; then
cat $HOME/.ruby-version
return
fi
false
}
_auto-chruby() {
local ruby_version=$(_ruby-version)
if [[ -n "${ruby_version}" ]]; then
chruby "${ruby_version}"
fi
}