1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
if [[ -f $HOME/.nix-profile/share/nix-direnv/direnvrc ]]; then
  source "$HOME/.nix-profile/share/nix-direnv/direnvrc"
fi

if [[ -n ${HOMEBREW_PREFIX-} && -f $HOMEBREW_PREFIX/share/chruby/chruby.sh ]]; then
  source "$HOMEBREW_PREFIX/share/chruby/chruby.sh"
fi

layout_k8s() {
  if [ $commands[kubectl] ]; then
    source <(kubectl completion zsh)
  fi
}

# https://github.com/direnv/direnv/issues/98#issuecomment-33677881
# use_ruby() {
#   local ver=$1
#   if [[ -z $ver ]] && [[ -f .ruby-version ]]; then
#     ver=$(cat .ruby-version)
#   fi
#   if [[ -z $ver ]]; then
#     echo Unknown ruby version
#     exit 1
#   fi
#   chruby $ver
#
#   layout ruby
#
#   # For some reason, the PATH order is unstable and sometimes Ruby's
#   # bin directory is in front of the direnv one, so force the direnv
#   # bin directory to take precedence
#   PATH_add ./.direnv/bin
# }

# https://github.com/direnv/direnv/wiki/ruby#-ruby-install
use_ruby() {
  local version=$1

  # Get version from .ruby-version if not specified
  if [[ -z $version ]] && [[ -f .ruby-version ]]; then
    version=$(cat .ruby-version)
  fi

  # Find matching version (exact or prefix match)
  if [[ -n $version ]] && [[ ! -d $HOME/.rubies/$version ]]; then
    version=$(ls -1 $HOME/.rubies | grep "^ruby-$version" | sort -V | tail -1)
  fi

  # Fall back to latest version if still no match
  if [[ -z $version ]]; then
    version=$(ls -1 $HOME/.rubies | sort -V | tail -1)
  fi

  local ruby_root=$HOME/.rubies/$version
  load_prefix "$ruby_root"
  layout_ruby
}

# https://hynek.me/articles/python-virtualenv-redux/#:~:text=Then%2C%20I%20add%20the%20following%20to%20the%20project%E2%80%99s%20%2Eenvrc%3A
use_uv() {
  test -d .venv || uv venv
  source .venv/bin/activate
  uv sync
}