-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathdot_bashrc
391 lines (302 loc) · 12 KB
/
dot_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
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# -*-mode:bash-*- vim:ft=bash
# ~/.bashrc
# =============================================================================
# Executed by bash for non-login shells.
#
# See https://www.gnu.org/software/bash/manual/html_node/index.html
# shellcheck shell=bash
# shellcheck source=/dev/null
# If not running interactively, don't do anything.
case $- in
*i*) ;;
*) return;;
esac
# General
# -----------------------------------------------------------------------------
# Check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# Matches filenames in a case-insensitive fashion when doing filename expansion.
shopt -s nocaseglob;
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# Do not autocomplete when accidentally pressing Tab on an empty line.
shopt -s no_empty_cmd_completion;
# Do not overwrite files when redirecting using ">" (override this with ">|").
set -o noclobber;
# Set preferred editor for local and remote sessions.
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='vim'
elif command -v mvim > /dev/null; then
export EDITOR='mvim'
else
export EDITOR='vim'
fi
# Configure less:
# F: automatically exit if the entire file can be displayed in first screen.
# I: case-insensitive search.
# R: Show ANSI colors.
# S: Truncate long lines.
# X: Prevent clearing the screen when exiting.
# See: https://relentlesscoding.com/2019/01/06/make-less-options-permanent-or-the-missing-lessrc/
export LESS="FIRSX"
# Make less more friendly for non-text input files.
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# History
# -----------------------------------------------------------------------------
# Append to the history file, don't overwrite it.
shopt -s histappend;
# Keep invalid history operation entries.
shopt -s histreedit;
# Ignore commands that start with spaces, and ignore consecutive duplicates.
# This is a verbose way of saying `ignoreboth`.
export HISTCONTROL=ignorespace:ignoredups;
# Keep a reasonably long history.
export HISTSIZE=4096;
# Keep even more history lines inside the file, so we can still look up
# previous commands without needlessly cluttering the current shell's history.
export HISTFILESIZE=16384;
# Keep track of the time the commands were executed.
# The xterm colour escapes require special care when piping; e.g. "| less -R".
export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S ";
# Allow going up (CTRL+R) and down (CTRL+S) shell history.
[[ $- == *i* ]] && stty -ixon
# Colors
# -----------------------------------------------------------------------------
# Set colors for dark Terminal themes.
export CLICOLOR=1;
export LSCOLORS=GxFxCxDxBxegedabagaced;
# Enable color support of ls.
if [ -x /usr/bin/dircolors ]; then
# shellcheck disable=SC2015
test -r "$HOME"/.dircolors && eval "$(dircolors -b "$HOME"/.dircolors)" || eval "$(dircolors -b)"
fi
# Enable colored GCC warnings and errors.
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# Prompt
# -----------------------------------------------------------------------------
# Uncomment for a colored prompt, if the terminal has the capability.
#force_color_prompt=yes
# Set a fancy prompt (non-color, unless we know we "want" color).
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
if [ -n "${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
unset force_color_prompt
# Set variable identifying the chroot you work in (see default prompt below).
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# Make default first prompt string informative, and optionally colorful.
# Basic style: "user@hostname:/current/path$ "
# Date style: "
# [01 Jan, 14:00:00] user@hostname:/current/path$ "
if [ "$color_prompt" = yes ]; then
# Basic style
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# Date style
PS1="\n\[\033[31m\][\D{%d %b}, \t] ${debian_chroot:+($debian_chroot)}\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ ";
SUDO_PS1="\n[\D{%d %b}, \t] ${debian_chroot:+($debian_chroot)}\[\e[90;01;41m\]\u@\h\[\e[0m\]:\$PWD\$ ";
export SUDO_PS1
else
# Basic style
PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w\$ "
# Date style
PS1="\n[\D{%d %b}, \t] $PS1"
fi
# Xterm
# -----------------------------------------------------------------------------
# If this is an xterm set the title to "user@host:dir".
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# Set Xterm/screen/Tmux title with only a short hostname.
# Uncomment this (or set SHORT_HOSTNAME to something else),
# Will otherwise fall back on $HOSTNAME.
SHORT_HOSTNAME=$(hostname -s)
export SHORT_HOSTNAME
# Set Xterm/screen/Tmux title with only a short username.
# Uncomment this (or set SHORT_USER to something else),
# Will otherwise fall back on $USER.
export SHORT_USER="${USER:0:8}"
# Set Xterm/screen/Tmux title with shortened command and directory.
# Uncomment this to set.
export SHORT_TERM_LINE=true
# Bash-It Framework
# -----------------------------------------------------------------------------
# Hide default user from local prompt
export DEFAULT_USER="${USER}"
# Path to the bash it configuration
export BASH_IT="${HOME}/.bash-it"
# Lock and Load a custom theme file.
# Leave empty to disable theming.
# location /.bash_it/themes/
if [ "$color_prompt" = yes ]; then
export BASH_IT_THEME='agnoster'
fi
unset color_prompt
# (Advanced): Change this to the name of your remote repo if you
# cloned bash-it with a remote other than origin such as `bash-it`.
# export BASH_IT_REMOTE='bash-it'
# Your place for hosting Git repos. You can use this for private repos.
# export GIT_HOSTING='[email protected]'
# Don't check mail when opening terminal.
unset MAILCHECK
# Change this to your console based IRC client of choice.
#export IRC_CLIENT='irssi'
# Set this to the command you use for todo.txt-cli manager.
#export TODO="t"
# Set this to false to turn off version control status checking within the
# prompt for all themes.
export SCM_CHECK=true
# Set vcprompt executable path for scm advance info in prompt (demula theme).
# See https://github.com/djl/vcprompt
#export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt
# Make Bash-it reload itself automatically after enabling or disabling aliases,
# plugins, and completions.
# Uncomment this to set.
export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=1
# Make Bash-it create alias reload.
# Uncomment this to set.
# export BASH_IT_RELOAD_LEGACY=1
# Load Bash It (if installed).
[ -s "${BASH_IT}/bash_it.sh" ] && \. "${BASH_IT}/bash_it.sh"
# Command-line shell completions
# -----------------------------------------------------------------------------
# Enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
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
# Provide known hosts completions.
# See http://surniaulula.com/2012/09/20/autocomplete-ssh-hostnames/
# shellcheck disable=SC2063
_complete_hosts () {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
host_list=$({
for c in /etc/ssh_config /etc/ssh/ssh_config "$HOME"/.ssh/config
do [ -r "$c" ] && sed -n -e 's/^Host[[:space:]]//p' -e 's/^[[:space:]]*HostName[[:space:]]//p' "$c"
done
for k in /etc/ssh_known_hosts /etc/ssh/ssh_known_hosts "$HOME"/.ssh/known_hosts
do [ -r "$k" ] && grep -E -v '^[#\[]' "$k"|cut -f 1 -d ' '|sed -e 's/[,:].*//g'
done
sed -n -e 's/^[0-9][0-9\.]*//p' /etc/hosts; }|tr ' ' '\n'|grep -v '*')
COMPREPLY=("$(compgen -W "$host_list" -- "$cur")")
return 0
}
for h in host ping ssh sshs telnet
do complete -F _complete_hosts $h
done
unset h
# Provide Homebrew completions (if installed).
# See https://docs.brew.sh/Shell-Completion
if type brew &> /dev/null; then
HOMEBREW_PREFIX="$(brew --prefix)"
if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then
\. "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
else
for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*; do
[[ -r "$COMPLETION" ]] && \. "$COMPLETION"
done
fi
unset HOMEBREW_PREFIX COMPLETION
fi
# Provide Chezmoi completions (if installed).
# See https://github.com/twpayne/chezmoi/blob/master/docs/REFERENCE.md
if command -v chezmoi > /dev/null; then
eval "$(chezmoi completion bash)"
fi
# Development environments
# -----------------------------------------------------------------------------
# Enable ASDF Extendable version manager (https://asdf-vm.com).
# This should replace all language-secific version managers.
ASDF_DIR="${ASDF_DIR:-$HOME/.asdf}"
if [[ ! -d $ASDF_DIR ]] && type brew &> /dev/null; then
ASDF_DIR="$(brew --prefix asdf)"
fi
[ -s "$ASDF_DIR/asdf.sh" ] && \. "$ASDF_DIR/asdf.sh"
# Provide ASDF completions (already loaded if using Homebrew).
[ -s "$ASDF_DIR/completions/asdf.bash" ] && \. "$ASDF_DIR/completions/asdf.bash"
# Enable Node Version Manager.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Provide Node completions.
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# Enable Python version management.
if command -v pyenv > /dev/null; then
eval "$(pyenv init -)"
fi
# Provide Python completions.
if command -v pipenv > /dev/null; then
eval "$(pipenv --completion)"
fi
# Load Ruby version management.
if command -v rbenv > /dev/null; then
eval "$(rbenv init -)"
fi
# Add Ruby gems to PATH.
if command -v ruby > /dev/null && command -v gem > /dev/null; then
PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin:$PATH"
fi
# Provide Travis CI completions.
[ -f "$HOME"/.travis/travis.sh ] && \. "$HOME"/.travis/travis.sh
# Register Acquia Dev Desktop
if [ -d "/Applications/DevDesktop" ]; then
export PATH="$PATH:/Applications/DevDesktop/tools"
export PATH="$PATH:/Applications/DevDesktop/drush_9"
fi
# Provide Drush completions.
#[ -f ${HOME}/.drush/drush.bashrc ] && \. ${HOME}/.drush/drush.bashrc
# Provide Drush prompt customizations.
#[ -f ${HOME}/.drush/drush.prompt.sh ] && \. ${HOME}/.drush/drush.prompt.sh
# Varia
# -----------------------------------------------------------------------------
# Point ripgrep to its configuration file.
# See https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md
export RIPGREP_CONFIG_PATH="$HOME/.ripgreprc"
# Includes
# -----------------------------------------------------------------------------
# Load functions declarations from separate configuration file.
if [ -f "$HOME"/.bash_functions ]; then
\. "$HOME"/.bash_functions
fi
# Load alias definitions from separate configuration file.
if [ -f "$HOME"/.bash_aliases ]; then
\. "$HOME"/.bash_aliases
fi
# Load custom code from separate configuration file.
if [ -f "$HOME"/.bash_extras ]; then
\. "$HOME"/.bash_extras
fi
# Finalization
# -----------------------------------------------------------------------------
# Add missing paths to PATH.
if [ -d "/usr/local/sbin" ]; then
export PATH="/usr/local/sbin:$PATH"
fi
# Remove any duplicate paths.
# See https://stackoverflow.com/questions/11650840/remove-redundant-paths-from-path-variable
PATH="$(echo "$PATH" | awk 'BEGIN{RS=":";}
{sub(sprintf("%c$",10),"");if(A[$0]){}else{A[$0]=1;
printf(((NR==1)?"":":")$0)}}')";
export PATH