-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_bashrc
More file actions
331 lines (276 loc) · 11.9 KB
/
_bashrc
File metadata and controls
331 lines (276 loc) · 11.9 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# .bashrc
### Uncomment for error checking .bashrc
# set -eE -o functrace
# file1=f1
# file2=f2
# file3=f3
# file4=f4
# failure() {
# local lineno=$1
# local msg=$2
# echo "Failed at $lineno: $msg"
# sleep 60
# }
# trap 'failure ${LINENO} "$BASH_COMMAND"' ERR
#####################################################
####### Profile slow .bashrc code - part 1/2 ########
#####################################################
## https://www.rosipov.com/blog/profiling-slow-bashrc/s
# PS4='+ $(date "+%s.%N")\011 '
# exec 3>&2 2>/tmp/bashstart.$$.log
# set -x
#####################################################
############ Source global definitions ##############
#####################################################
# Set default editor
export VISUAL=vim
EDITOR=vim
export EDITOR
# Load composure first, so we support function metadata
. "${HOME}/stablecaps_bashrc/modules/composure.sh"
# support 'plumbing' metadata
cite _about _param _example _group _author _version
# Source bashrc assets
. "${HOME}/stablecaps_bashrc/theme_settings.sh"
. "${HOME}/stablecaps_bashrc/internal/internal_colour_functions.sh"
. "${HOME}/stablecaps_bashrc/internal/internal_helper_functions.sh"
. "${HOME}/stablecaps_bashrc/internal/internal_colour_defs.sh"
. "${HOME}/stablecaps_bashrc/internal/internal_git_functions.sh"
### Comment/uncomment to activate LS_COLORS - Additional defs can be added using vivid
. "${HOME}/stablecaps_bashrc/internal/internal_ls_colors_defs.sh"
LS_COLORS=$ayu_modified
export LS_COLORS
# source aliases
. "${HOME}/stablecaps_bashrc/aliases/_core-bash_aliases.sh"
. "${HOME}/stablecaps_bashrc/aliases/docker_aliases.sh"
. "${HOME}/stablecaps_bashrc/aliases/docker-compose_aliases.sh"
. "${HOME}/stablecaps_bashrc/aliases/git_aliases.sh"
if command -v apt &> /dev/null; then
. "${HOME}/stablecaps_bashrc/aliases/apt_aliases.sh"
fi
#
. "${HOME}/stablecaps_bashrc/aliases/terraform_aliases.sh"
### TODO: fix bug with slow completions
# source completions
# if ! shopt -oq posix; then
# if [ -f /usr/share/bash-completion/bash_completion ]; then
# . /usr/share/bash-completion/bash_completion
# elif [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
# fi
# fi
# . "${HOME}/stablecaps_bashrc/completions/docker_completion.sh"
# . "${HOME}/stablecaps_bashrc/completions/docker-compose_completion.sh"
# . "${HOME}/stablecaps_bashrc/completions/awscli_completion.sh"
# . "${HOME}/stablecaps_bashrc/completions/git_completion.sh"
# source bash modules
. "${HOME}/stablecaps_bashrc/modules/aws_module.sh"
. "${HOME}/stablecaps_bashrc/modules/base_module.sh"
. "${HOME}/stablecaps_bashrc/modules/extract.sh"
. "${HOME}/stablecaps_bashrc/modules/docker_module.sh"
. "${HOME}/stablecaps_bashrc/modules/docker-compose_module.sh"
. "${HOME}/stablecaps_bashrc/modules/git_module.sh"
. "${HOME}/stablecaps_bashrc/modules/history_module.sh"
. "${HOME}/stablecaps_bashrc/modules/installer_module.sh"
# . "${HOME}/stablecaps_bashrc/modules/ssh_helper_module.sh"
#. "${HOME}/stablecaps_bashrc/modules/ssh-agent_module.sh"
#################################################################
# make less more friendly for non-text input files, see lesspipe
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# Color for manpages in less makes manpages a little easier to read
export LESS_TERMCAP_mb=$'\E[38;5;221m'
export LESS_TERMCAP_md=$'\E[38;5;221m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;35m'
#################################################################
# enable dircolor support
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
fi
#####################################################
################ Set SHELL Options ##################
#####################################################
# enter a few characters and press UpArrow/DownArrow
# to search backwards/forwards through the history
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]
then
# https://codeinthehole.com/tips/the-most-important-command-line-tip-incremental-history-searching-with-inputrc/
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
bind '"\e[C":forward-char'
bind '"\e[D":backward-char'
fi
##########################################
# history guide: https://www.digitalocean.com/community/tutorials/how-to-use-bash-history-commands-and-expansions-on-a-linux-vps
HISTCONTROL=ignoreboth # don't put duplicate lines or lines starting with space in the history.
export HISTSIZE=100000 # big big history
export HISTFILESIZE=100000 # big big history
shopt -s histappend
# shopt -s cmdhist # save all lines of a multiple-line command in the same history entry <- really bad idea
shopt -s cdspell # corrects minor cd spelling errors
# shopt -s cdable_vars # non-dir args supplied to cd are assumned to be vars
shopt -s no_empty_cmd_completion # tell bash/completion to NOT try completion for an empty entry
# https://superuser.com/questions/288714/bash-autocomplete-like-zsh
if [[ $- == *i* ]]; then
bind 'set show-all-if-ambiguous on'
bind 'set colored-completion-prefix on'
fi
#####################################################
################ PS Command Prompt ##################
#####################################################
force_color_prompt="" #"yes"
if [ -z "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
# SET_FULL_PROMPT" # set in theme_settings.sh
if [ "$color_prompt" == "yes" ]; then
if [ "$SET_FULL_PROMPT" == "full" ] ; then
function prompt_command() {
# Custom fully featured 3 line prompt with most git support
###################################################
### identify success/fail status of last command
### DO NOT MOVE THIS VARIABLE: must be first!
local last_status="$?"
###################################################
###################################################
### Setup if else for different color themes
PATH_COL_VAR="${SET_PATHCOL_VAR}"
PATH_COL="${SET_PATHCOL}"
THEME_VAR="${SET_THEME_VAR}"
BARCOL="${SET_BARCOL}"
TXTCOL="${SET_TXTCOL}"
###################################################
### Turn the prompt symbol red if the user is root
### root stuff
if [[ $(id -u) -eq 0 ]]; then
### root color
BARCOL="${MORANGE}"
TXTCOL="${RED}"
local ENDBIT="#"
else
local ENDBIT="$"
fi # root bit
###################################################
### Display virtual environment notification if applicable
## disable the default virtualenv prompt change
export VIRTUAL_ENV_DISABLE_PROMPT=1
VIRTENV=$(_virtualenv_info)
### Display ssh variable notification in prompt if applicable
SSH_SESSION=$(_ssh_info)
### Display AWS profile if applicable
CURR_AWS_PROFILE=$(_aws_info)
# Display tty no in prompt
local TTY_VAR=`tty 2> /dev/null | awk -F/ '{nlast = NF 0;print $nlast$NF": "}'`
###################################################
### set color coded error string for prompt depending on success of last command
if [[ $last_status == 0 ]]; then
ERRPROMPT="\[\033[1;1;32m\]${ENDBIT} "
else
ERRPROMPT='\[\033[1;1;31m\]X '
fi
###################################################
### set titlebar
local TITLEBAR=`_pwdtail`
echo -ne '\033]2;'${TTY_VAR}${TITLEBAR}'\007'
## move out of indented tabs to avoid formatting horror (still in function)
PS1="${debian_chroot:+($debian_chroot)}\n\
${BARCOL}┌──\
${TXTCOL}[\u]\
${BARCOL}─\
${TXTCOL}[\H]\
$(_parse_git)\
${VIRTENV}${SSH_SESSION}${CURR_AWS_PROFILE}
${BARCOL}│${DKGRAY}${TTY_VAR}${PATH_COL}> \w \
\n${BARCOL}└──\
${TXTCOL}`date +"%H:%M"`\
${BARCOL}─\
${ERRPROMPT}${TERGREEN}"
}
elif [ "$SET_FULL_PROMPT" == "mid" ]; then
function prompt_command() {
###################################################
### identify success/fail status of last command
### DO NOT MOVE THIS VARIABLE: must be first!
local last_status="$?"
###################################################
# Custom partially featured 2 line prompt with minimal git support
PATH_COL_VAR="${SET_PATHCOL_VAR}"
PATH_COL="${SET_PATHCOL}"
THEME_VAR="${SET_THEME_VAR}"
BARCOL="${SET_BARCOL}"
TXTCOL="${SET_TXTCOL}"
###################################################
### Display virtual environment notification if applicable
## disable the default virtualenv prompt change
export VIRTUAL_ENV_DISABLE_PROMPT=1
VIRTENV=$(_virtualenv_min_info)
### Display ssh variable notification in prompt if applicable
SSH_SESSION=$(_ssh_info)
### get parent directory
FULL_PATH=$(pwd)
LAST2_DIR=${FULL_PATH#"${FULL_PATH%/*/*}/"}
###################################################
### set color coded error string for prompt depending on success of last command
if [[ $last_status == 0 ]]; then
ERRPROMPT="\[\033[1;1;32m\]$ "
else
ERRPROMPT='\[\033[1;1;31m\]X '
fi
###################################################
#DRIVE_PATH=$(df . | tail -1 | awk '{print $1}')
#DRIVE_ID=${DRIVE_PATH#"${DRIVE_PATH%/*}/"}
## move out of indented tabs to avoid formatting horror (still in function)
PS1="${debian_chroot:+($debian_chroot)}\n\
${BARCOL}\
${TXTCOL}(`date +"%H:%M"`)${BARCOL}─${TXTCOL}(\u@\H)\
${BARCOL}─${GRAY}(${GRAY}${LAST2_DIR})\
$(_parse_git_minimal)\n\
${BARCOL}\
${RED}${VIRTENV} ${ERRPROMPT}${TERGREEN}"
}
else # $SET_FULL_PROMPT != "yes" or "mid"
function prompt_command() {
# basic ubuntu color prompt
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
}
#unset color_prompt force_color_prompt
fi
else # color_prompt !="yes"
function prompt_command() {
# very basic ubuntu non-color prompt
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
}
#unset color_prompt force_color_prompt
fi
### Prompt command
PROMPT_COMMAND="prompt_command"
#####################################################
############### Set EnvironmentVars #################
#####################################################
# Entry for directory autojump: https://github.com/wting/autojump
# needs to be at end
[[ -s ${HOME}/.autojump/etc/profile.d/autojump.sh ]] && source ${HOME}/.autojump/etc/profile.d/autojump.sh
#####################################################
####### Profile slow .bashrc code - part 2/2 ########
#####################################################
# set +x
# exec 2>&3 3>&-
#####################################################
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
#. "$HOME/.cargo/env"
export PATH=$HOME/.cargo/bin:$PATH
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin