-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.direnvrc
More file actions
74 lines (66 loc) · 2 KB
/
Copy path.direnvrc
File metadata and controls
74 lines (66 loc) · 2 KB
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
65
66
67
68
69
70
71
72
73
74
# Example: export_alias zz "ls -la"
export_alias() {
local name=$1
shift
local alias_dir=$PWD/.direnv/aliases
local target="$alias_dir/$name"
mkdir -p "$alias_dir"
if ! [[ ":$PATH:" == *":$alias_dir:"* ]]; then
PATH_add "$alias_dir"
fi
echo "#!/usr/bin/env bash -e" > "$target"
echo "$@ \$@" >> "$target"
chmod +x "$target"
}
layout_miniconda() {
local ACTIVATE="/opt/homebrew/Caskroom/miniconda/base/bin/activate"
if [ -n "$1" ]; then
# Explicit environment name from layout command.
local env_name="$1"
source $ACTIVATE ${env_name}
elif (grep -q name: environment.yml); then
# Detect environment name from `environment.yml` file in `.envrc` directory
source $ACTIVATE `grep name: environment.yml | sed -e 's/name: //' | cut -d "'" -f 2 | cut -d '"' -f 2`
else
(>&2 echo No environment specified);
exit 1;
fi;
}
layout_poetry() {
PYPROJECT_TOML="${PYPROJECT_TOML:-pyproject.toml}"
if [[ ! -f "$PYPROJECT_TOML" ]]; then
log_status "No pyproject.toml found. Executing \`poetry init\` to create a \`$PYPROJECT_TOML\` first."
poetry init
fi
if [[ -d ".venv" ]]; then
VIRTUAL_ENV="$(pwd)/.venv"
else
VIRTUAL_ENV=$(poetry env info --path 2>/dev/null ; true)
fi
if [[ -z $VIRTUAL_ENV || ! -d $VIRTUAL_ENV ]]; then
log_status "No virtual environment exists. Executing \`poetry install\` to create one."
poetry install
VIRTUAL_ENV=$(poetry env info --path)
fi
PATH_add "$VIRTUAL_ENV/bin"
export POETRY_ACTIVE=1
export VIRTUAL_ENV
}
use_zig() {
if [ -z "$1" ]; then
log_status "No Zig version specified, using master"
version="master"
else
version="$1"
fi
export ZIG_HOME=$(zigup get-install-dir)$version/files
if [ ! -d "$ZIG_HOME" ]; then
log_status "Zig $version not found at $ZIG_HOME, downloading"
zigup fetch $version
fi
if [ ! -d "$ZIG_HOME" ]; then
log_error "Failed to download Zig $version"
return 1
fi
PATH_add "$ZIG_HOME"
}