-
Notifications
You must be signed in to change notification settings - Fork 0
/
.direnvrc
186 lines (139 loc) · 4.14 KB
/
.direnvrc
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
# -*- mode: sh; -*-
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
reset="$(tput sgr0)"
_fail() {
(>&2 printf "${red}%s${reset}\n" "${1}")
return 1
}
_warn() {
(>&2 printf "${yellow}%s${reset}\n" "${1}")
return 0
}
_info() {
(>&2 printf "${green}%s${reset}\n" "${1}")
return 0
}
_notice() {
(>&2 printf "${blue}%s${reset}\n" "${1}")
return 0
}
# sets tab name and color in iTerm2
layout_tab() {
local title="${1:-$(basename "$(pwd)")}"
local color="${2:-default}"
printf '\e]1;%s\a' "${title}"
echo -en "\033]0;${title}\a"
[[ -z "${color}" ]] && return
if ! [[ -f "${HOME}/.iterm2/it2setcolor" ]]; then
_fail "to use custom tab settings, please install the iTerm2 Shell Integration"
return 1
fi
# Mac OS tags
[[ "$color" == "yellow" ]] && color=p3:eddd68
[[ "$color" == "orange" ]] && color=p3:ecb05b
[[ "$color" == "purple" ]] && color=p3:b990d5
[[ "$color" == "pink" ]] && color=p3:d189e2
[[ "$color" == "green" ]] && color=p3:b6dc60
[[ "$color" == "blue" ]] && color=p3:6fa2f1
[[ "$color" == "red" ]] && color=p3:ea7468
~/.iterm2/it2setcolor tab "${color}"
}
# use a specific Node.js version
use_nodejs() {
set -eo pipefail
[ -s "/usr/local/opt/nvm/nvm.sh" ] && source "/usr/local/opt/nvm/nvm.sh"
has nvm || return 1
export PATH="${PATH}:./node_modules/.bin"
if [[ -f .nvmrc ]]; then
nvm use
return $?
fi
local version="${1:-${NVM_VERSION}}"
if [[ -z "${version}" ]]; then
_fail "you should specify a Node.js version or add a .nvmrc file to the project root"
return 1
fi
nvm use "${version}"
}
# use a certain Python version
use_python() {
set -eo pipefail
has pyenv || return 1
eval "$(pyenv init --path)"
local pyversion="${1:-${PYENV_VERSION}}"
[[ -f .python-version ]] && pyversion="$(head .python-version)"
if [[ -z "${pyversion}" ]]; then
_fail "you should specify a python version or add a .python-version file to the project root"
return 1
fi
if ! pyenv versions --bare | grep "${pyversion}"; then
echo "Installing Python ${pyversion}"
pyenv install --skip-existing "${pyversion}"
fi
if ! [[ -f .python-version ]]; then
pyenv shell "${pyversion}"
fi
}
layout_venv() {
set -eo pipefail
local venv="${1:-.venv}"
[[ -d ${venv} ]] || python -m venv .venv
# `virtualenv` has been deprecated in favor of `python -m venv`
# has virtualenv && virtualenv -p "$(pyenv which python)" "${venv}"
# shellcheck disable=SC1091
source "${venv}/bin/activate"
}
layout_virtualenv() {
layout_venv "${@}"
}
# use a certain Java version
use_java() {
set -eo pipefail
has jenv || return 1
[[ "${JENV_LOADED}" == "1" ]] || eval "$(jenv init -)"
local java_version="${1:-}"
[[ -f .java-version ]] && java_version="$(head .java-version)"
if [[ -z "${java_version}" ]]; then
_fail "you should specify a Java version or add a .java-version file to the project root"
return 1
fi
if ! [[ -f .java-version ]]; then
jenv shell "${java_version}"
fi
export JAVA_HOME
JAVA_HOME="$(jenv javahome)"
}
# Configure Databricks plugin
use_databricks() {
set -eo pipefail
if [[ -z "${PYENV_ROOT}" ]]; then
_fail "you should have Python to setup Databricks"
return 1
fi
if ! (has databricks); then
pip install -U databricks-cli
[[ -f ~/.databrickscfg ]] || databricks configure --token
fi
if ! (has databricks-connect); then
_warn "databricks-connect is not installed"
return 1
fi
export DB_CONNECT_RUNTIME
DB_CONNECT_RUNTIME="$(pip show databricks-connect | grep 'Version' | grep -o '\d.\d')"
export SPARK_HOME
SPARK_HOME="$(dirname "$(databricks-connect get-jar-dir)")"
}
layout_aws() {
local profile="${1:-default}"
_info "Loading AWS credentials from profile '${profile}'"
export AWS_PROFILE
AWS_PROFILE="${profile}"
export AWS_ACCESS_KEY_ID
AWS_ACCESS_KEY_ID="$(grep -A2 "\[${profile}\]" ~/.aws/credentials | awk -F ' = ' '/aws_access_key_id/ {print $2}')"
export AWS_SECRET_ACCESS_KEY
AWS_SECRET_ACCESS_KEY="$(grep -A2 "\[${profile}\]" ~/.aws/credentials | awk -F ' = ' '/aws_secret_access_key/ {print $2}')"
}