-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc
159 lines (121 loc) · 3.56 KB
/
bashrc
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
# do nothing in non interactive mode
if [ -z "$PS1" ]; then
return
fi
export TERM=linux
[ -t 0 ] && stty -iexten # if stdin is open disable xon/xoff flow control (^Q, ^S)
PATH="/opt/pkg/bin/bash:$HOME/bin:$PATH"
function path_if() {
[ -d "$1" ] && PATH="$1:$PATH"
}
function source_if() {
[ -r "$1" ] && source "$1"
}
function export_if() {
[ -x "$2" ] && export "$1"="$2"
}
path_if /usr/local/bin
export PATH
EDITOR=nvim
export EDITOR
export GIT_EDITOR="$EDITOR -f"
export_if SVN_EDITOR "$HOME/bin/svneditor"
export_if GIT_EDITOR "$HOME/bin/giteditor"
export_if HG_EDITOR "$HOME/bin/hgeditor"
export PAGER=less
# make less pass through ANSI color codes so you can see colors in the pager
export LESS="-R"
# if you pipe through $PAGER and see color escape codes try to pipe through stripcolor first
alias stripcolor='sed "s/\[[0-9;]*m//g"'
source_if /usr/local/git/contrib/completion/git-completion.bash
source_if /usr/local/git/contrib/completion/git-prompt.sh
source_if /usr/share/bash-completion/completions/git
source_if /etc/bash_completion.d/git-prompt
# Show most used commands from bash history
function usage {
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
}
# Change xterm title
function title {
printf '\33]2;%s\007' "$*"
}
source_if "$HOME/.bashrc.local"
source_if "$HOME/.bashrc.k8s"
function reqs {
PIP=$VIRTUAL_ENV/bin/pip
[ -e requirements-dev.txt ] && $PIP install -r requirements-dev.txt && return
[ -e setup.py ] && pip install -e . && $PIP install -e '.[test]'
[ -e requirements.txt ] && $PIP install -r requirements.txt
}
function venv {
local VENV_HOME=$HOME/venv
local PROJECT="$1"
if [ -z "${PROJECT}" ]; then
PROJECT=$(basename "$(pwd)")
fi
if [ -d $VENV_HOME/$PROJECT ]; then
echo "Activating ${PROJECT} venv"
else
echo "Creating ${PROJECT} venv"
/usr/local/bin/python3.6 -m venv $VENV_HOME/$PROJECT
reqs
fi
source "$VENV_HOME/$PROJECT/bin/activate"
}
alias v=venv
alias pt=pytest
alias px='pytest -x'
alias pf='pytest --lf'
alias ga='git add -i'
alias gd='git diff'
alias gm='git commit'
alias gs='git status'
alias nopyc='find . -name \*.pyc -delete'
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWUPSTREAM=auto
export VIRTUAL_ENV_DISABLE_PROMPT=1
function prompt_command() {
# force __git_ps1 and virtualenv to play nice
# Runs every single time the prompt is displayed
# http://mivok.net/2013/06/10/bash_prompt.html
GITPROMPT=
if type -p __git_ps1; then
GITPROMPT=$(__git_ps1 "%s")
fi
if [[ -n $GITPROMPT ]]; then
GITPROMPT=" [${GITPROMPT}]"
fi
VENVPROMPT=${VIRTUAL_ENV##*/}
if [[ -n $VENVPROMPT ]]; then
VENVPROMPT="(${VENVPROMPT})"
fi
NOW=$(date +'%m-%d %H:%M')
K8SPROMPT=$(kprompt 2>/dev/null)
if [[ -n $K8SPROMPT ]]; then
K8SPROMPT="(${K8SPROMPT})"
fi
}
function setprompt() {
PS1="\w \$VENVPROMPT\$GITPROMPT \$K8SPROMPT [\$NOW] (\$?) $ "
export PS1
}
export PROMPT_COMMAND=prompt_command
setprompt
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
alias k=kubectl
if ! shopt -oq posix; then
source_if /etc/bash_completion
source_if "${HOME}/.kube/completion.bash.inc"
complete -F __start_kubectl k
fi
export ROC_ENABLE_PRE_VEGA=1
alias vim=nvim
alias v=nvim
alias nv=nvim
if [ -n "$(which rbenv)" ]; then
eval "$(rbenv init -)"
fi