-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbash_profile
121 lines (99 loc) · 3.49 KB
/
bash_profile
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
#!/usr/bin/env bash
export PATH=$PATH:$HOME/bin
export LC_ALL=en_US.UTF-8
# Improvement for the promt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# helper functions for Bash - easier coloring than using escape sequences
function Background() {
if [ -n "$ZSH_VERSION" ]; then
# assume Zsh
echo "$(tput setab $1)"
elif [ -n "$BASH_VERSION" ]; then
# assume Bash
echo "\[$(tput setab $1)\]"
fi
}
function Color() {
if [ -n "$ZSH_VERSION" ]; then
# assume Zsh
echo "$(tput setaf $1)"
elif [ -n "$BASH_VERSION" ]; then
# assume Bash
echo "\[$(tput setaf $1)\]"
fi
}
function ResetColor() {
if [ -n "$ZSH_VERSION" ]; then
# assume Zsh
echo "$(tput sgr0)"
elif [ -n "$BASH_VERSION" ]; then
# assume Bash
echo "\[$(tput sgr0)\]"
fi
}
# now you can add it to your prompt like this:
# function which configures the prompet...
function Prompt() {
local last_status=$?
local failure="✘"
local success="✔"
local time=$(date +"%H:%M:%S")
if [[ "$last_status" != "0" ]]; then
last_status="$(Color 5)$failure$(ResetColor)"
else
last_status="$(Color 2)$success$(ResetColor)"
fi
KUBE_CURRENT_CONTEXT=$(command -v kubectl >/dev/null 2>&1 && kubectl config current-context)
export KUBE_CURRENT_CONTEXT
aws_profile="$(Background 3)$(Color 7)${AWS_VAULT:-$AWS_PROFILE}$(ResetColor)"
git_branch="$(Color 5)$(parse_git_branch)$(ResetColor)"
k8s_context="$(Background 4)$(Color 7)$KUBE_CURRENT_CONTEXT$(ResetColor)"
echo "$time $last_status $USER@$HOST:$PWD"
second_line="$aws_profile $k8s_context $git_branch"
# Add conda environment to prompt
if [ ! -z "$CONDA_DEFAULT_ENV" ]
then
second_line+="$(Background 7)$(Color 6)($CONDA_DEFAULT_ENV)$(ResetColor)"
fi
[[ "X${second_line}X" != "X X" ]] && echo $second_line
echo "$ "
}
# git completion
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
# AWS specific commands
function aws_docker_login() {
aws_account_id=$1
region=$2
echo "aws ecr get-login-password --region $region | docker login --username AWS --password-stdin ${aws_account_id}.dkr.ecr.${region}.amazonaws.com"
}
# ...and the hook which updates the prompt whenever we run a command
PROMPT_COMMAND='PS1=$(Prompt)'
precmd() {
eval "$PROMPT_COMMAND"
}
if [ -n "$ZSH_VERSION" ]; then
# assume Zsh
autoload -Uz compinit
compinit
command -v kubectl && source <(kubectl completion zsh)
elif [ -n "$BASH_VERSION" ]; then
# assume Bash
command -v kubectl && source <(kubectl completion zsh)
else
# asume something else
echo "Cannot recognize the sh"
fi
[[ -r "$HOME/.custom-aliases" ]] && source $HOME/.custom-aliases
[[ -r "$HOME/.custom_profile" ]] && source $HOME/.custom_profile
# Machine specific
if [ -f $HOME/.bash_profile_this_machine_specific ]; then
source $HOME/.bash_profile_this_machine_specific
fi
# Terraform specific
export TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache
export TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE=true
# Terragrunt specific
export TERRAGRUNT_PROVIDER_CACHE=1
export TERRAGRUNT_PROVIDER_CACHE_DIR=$HOME/.terragrunt.d/provider-cache