# vi: ft=sh # shellcheck shell=bash ZVM_DIRENV_VERSION=1.0.0 # Usage: zvm_direnv_version # # Checks that the nix-direnv version is at least as old as . zvm_direnv_version() { _require_version zvm-direnv $ZVM_DIRENV_VERSION "$1" } _require_version() { local cmd=$1 version=$2 required=$3 if ! printf "%s\n" "$required" "$version" | LC_ALL=C sort -c -V 2>/dev/null; then log_error \ "zvm_direnv: minimum required $(basename "$cmd") version is $required (installed: $version)" return 1 fi } use_zig() { if [[ -z $1 ]]; then log_error "Must specify a zig version!" return 1 fi if [[ "$1" == "master" ]]; then log_error "Please don't use master" return 1 fi if ! command -v "$1" > /dev/null 2>&1; then log_error "zvm not installed - please install it from https://www.zvm.app/" return 1 fi local version="$1" # This is a bad idea, because it will make a global change # zvm use $1 if [[ "$(zvm ls | grep "$version")" != "$version" ]]; then local current # zvm 0.7.9 does not indicate which version is in use, so we have to find # the version that was hard linked into the bin directory current="$(find "${ZVM_INSTALL}/.." -samefile "${ZVM_INSTALL}/../bin/zig" | \ rev | \ cut -d/ -f2 | \ rev)" zvm install --zls "$1" # I think this is safe for all except master # zvm install will automatically use the installed version, which is normally # cool, but in this case, we don't want to do that, so we will revert zvm use "$current" fi PATH_add "${ZVM_INSTALL}/../$1" }