forked from mohammedpivotal/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.direnvrc
90 lines (78 loc) · 2.33 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
.#-*- mode: sh; -*-
# This is a extra goodness for direnv
# adds
# use pcf-toolsmith <pcf-domain> <om-password>
# use pcf-pez <haas-id> <password>
# use pcf-terraform <domain> <om-password>
# use pcf [domain]
# use pcf-pas
# use pcf-pks
# To use just append content to your $HOME/.direnvrc. You may use following command to do same
export_function() {
local name=$1
local alias_dir=$PWD/.direnv/aliases
mkdir -p "$alias_dir"
PATH_add "$alias_dir"
local target="$alias_dir/$name"
if declare -f "$name" >/dev/null; then
echo "#!/usr/bin/env bash" > "$target"
declare -f "$name" >> "$target" 2>/dev/null
echo "$name \$*" >> "$target"
chmod +x "$target"
fi
}
use_python() {
if [ -n "$(which pyenv)" ]; then
local pyversion=$1
pyenv local ${pyversion}
fi
}
layout_virtualenv() {
local pyversion=$1
local pvenv=$2
if [ -n "$(which pyenv virtualenv)" ]; then
pyenv virtualenv --force --quiet ${pyversion} ${pvenv}-${pyversion}
fi
pyenv local --unset
}
layout_activate() {
if [ -n "$(which pyenv)" ]; then
source $HOME/.pyenv/versions/$1/bin/activate
fi
}
use_docker-machine(){
local env=${1:-default}
echo Docker machine: $env
local machine_cmd=$(docker-machine env --shell bash $env)
eval $(docker-machine env --shell bash $env)
export DOCKER_MACHINE_IP=$(docker-machine ip $env)
}
use_nvm() {
local node_version=$1
nvm_sh=~/.nvm/nvm.sh
if [[ -e $nvm_sh ]]; then
source $nvm_sh
nvm use $node_version
fi
}
use_aws-sso(){
profile=${1:-default}
env_file=${2:-$(direnv_layout_dir)/env-aws-sso}
export AWS_PROFILE=$profile
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
echo AWS_PROFILE: $AWS_PROFILE, Env File: $env_file
if ! aws sts get-caller-identity --profile $AWS_PROFILE &>> /dev/null
then
aws sso login --profile $AWS_PROFILE
if [[ -e $env_file ]] ; then rm $env_file ; fi
fi
mkdir -p $(direnv_layout_dir)
aws_cred=$(aws configure export-credentials --profile $AWS_PROFILE)
cat <<EOF > $env_file
export AWS_ACCESS_KEY_ID="$(echo $aws_cred |jq -r .AccessKeyId)"
export AWS_SECRET_ACCESS_KEY="$(echo $aws_cred |jq -r .SecretAccessKey)"
export AWS_SESSION_TOKEN="$(echo $aws_cred |jq -r .SessionToken)"
export AWS_EXPIRY="$(echo $aws_cred | jq -r .Expiration)"
EOF
dotenv_if_exists $env_file
}