# From https://github.com/direnv/direnv/wiki/Ruby#-chruby use_chruby() { local version version="${1}" [[ "${version}" == --auto ]] && version="$(read_version_file .ruby-version)" [[ -z "${version}" ]] && return local chruby if has brew; then local brew_prefix brew_prefix="$(brew --prefix)" if [[ -e "${brew_prefix}/opt/chruby/share/chruby/chruby.sh" ]]; then chruby="${brew_prefix}/opt/chruby/share/chruby/chruby.sh" fi fi [[ -z "${chruby}" ]] && [[ -e /usr/local/share/chruby/chruby.sh ]] && chruby=/usr/local/share/chruby/chruby.sh [[ -z "${chruby}" ]] && return source "${chruby}" chruby "${version}" } # From https://github.com/direnv/direnv/wiki/Find-Up-with-Alternates find_up_() { ( while true; do for v in "${@}"; do if [[ -f "${v}" ]]; then echo "${PWD}/${v}" return 0 fi done if [[ "${PWD}" == / ]] || [[ "${PWD}" == // ]]; then return 1 fi cd .. done ) } read_version_file() { local file file="$(find_up_ "${@}")" [[ -z "${file}" ]] && return watch_file "${file}" ruby -e "puts ARGF.readline" 2> /dev/null "${file}" } # From https://github.com/direnv/direnv/wiki/Node#using-nvm use_nvm() { local node_version="$1" source "${NVM_DIR}/nvm.sh" # This automatically does `nvm use` afterward. nvm install "$node_version" } # From https://github.com/direnv/direnv/wiki/Python#poetry layout_poetry() { if [[ ! -f pyproject.toml ]]; then log_error 'No pyproject.toml found. Use `poetry new` or `poetry init` to create one first.' exit 2 fi # Create venv if it doesn't exist poetry run true export VIRTUAL_ENV="$(poetry env info --path)" export POETRY_ACTIVE=1 PATH_add "$VIRTUAL_ENV/bin" }