forked from fharper/macsetup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
243 lines (195 loc) · 6.24 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
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
#PATH
export PATH="$HOME/.cargo/bin:$HOME/go/bin/:/usr/local/sbin:$HOME/Library/Python/3.7/bin/:$PATH"
#ls Directories in color
alias ls='ls -a $@'
# Tell ls to be colourful
export CLICOLOR=1
export LSCOLORS="Axfxcxdxbxegedabagacad"
# Append to the history file, don't overwrite it
shopt -s histappend
# Save all lines of a multiple-line command in the same history entry (allows easy re-editing of multi-line commands)
shopt -s cmdhist
# Do not autocomplete when accidentally pressing Tab on an empty line. (It takes forever and yields "Display all 15 gazillion possibilites?")
shopt -s no_empty_cmd_completion
# No install emoji for brew
export HOMEBREW_NO_EMOJI=1
#Increase the size of history maintained by BASH - variables defined below increase the number of history items and history file size (default value is 500):
export HISTSIZE=10000
#Ensure syncing (flushing and reloading) of .bash_history with in-memory history:
export PROMPT_COMMAND="history -a; history -c; history -r; ${PROMPT_COMMAND}"
#Use leading space to hide commands from history:
export HISTCONTROL=ignorespace
export HSTR_CONFIG=raw-history-view,hicolor,no-confirm
bind '"\C-r": "\C-ahstr -- \C-j"'
#####
#stolen from https://github.com/sapegin/dotfiles
#####
# Colors
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
WHITE="$(tput setaf 7)"
GRAY="$(tput setaf 8)"
BOLD="$(tput bold)"
UNDERLINE="$(tput sgr 0 1)"
INVERT="$(tput sgr 1 0)"
NOCOLOR="$(tput sgr0)"
# User color
case $(id -u) in
0) user_color="$RED" ;; # root
*) user_color="$GREEN" ;;
esac
# Symbols
prompt_symbol="❯"
prompt_clean_symbol="☀ "
prompt_dirty_symbol="☂ "
prompt_venv_symbol="☁ "
function prompt_command() {
# Local or SSH session?
local remote=
[ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] && remote=1
# Git branch name and work tree status (only when we are inside Git working tree)
local git_prompt=
if [[ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then
# Branch name
local branch="$(git symbolic-ref HEAD 2>/dev/null)"
branch="${branch##refs/heads/}"
# Working tree status (red when dirty)
local dirty=
# Modified files
git diff --no-ext-diff --quiet --exit-code --ignore-submodules 2>/dev/null || dirty=1
# Untracked files
[ -z "$dirty" ] && test -n "$(git status --porcelain)" && dirty=1
# Format Git info
if [ -n "$dirty" ]; then
git_prompt=" $RED$prompt_dirty_symbol$branch$NOCOLOR"
else
git_prompt=" $GREEN$prompt_clean_symbol$branch$NOCOLOR"
fi
fi
# Virtualenv
local venv_prompt=
if [ -n "$VIRTUAL_ENV" ]; then
venv_prompt=" $BLUE$prompt_venv_symbol$(basename $VIRTUAL_ENV)$NOCOLOR"
fi
# Only show username if not default
local user_prompt=
[ "$USER" != "$local_username" ] && user_prompt="$user_color$USER$NOCOLOR"
# Show hostname inside SSH session
local host_prompt=
[ -n "$remote" ] && host_prompt="@$YELLOW$HOSTNAME$NOCOLOR"
# Show delimiter if user or host visible
local login_delimiter=
[ -n "$user_prompt" ] || [ -n "$host_prompt" ] && login_delimiter=":"
# Format prompt
first_line="$user_prompt$host_prompt$login_delimiter$WHITE\w$NOCOLOR$git_prompt$venv_prompt"
# Text (commands) inside \[...\] does not impact line length calculation which fixes stange bug when looking through the history
# $? is a status of last command, should be processed every time prompt prints
second_line="\`if [ \$? = 0 ]; then echo \[\$CYAN\]; else echo \[\$RED\]; fi\`\$prompt_symbol\[\$NOCOLOR\] "
PS1="\n$first_line\n$second_line"
# Multiline command
PS2="\[$CYAN\]$prompt_symbol\[$NOCOLOR\] "
# Terminal title
local title="$PWD"
[ -n "$remote" ] && title="$title \xE2\x80\x94 $HOSTNAME"
echo -ne "\033]0;$title"; echo -ne "\007"
}
# Show awesome prompt only if Git is istalled
command -v git >/dev/null 2>&1 && PROMPT_COMMAND=prompt_command
#####
#####
# Rbenv #
#
eval "$(rbenv init -)"
# bash completion #
#
source $(brew --prefix)/etc/bash_completion
# Git completion #
#
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
# npm completion #
#
if type complete &>/dev/null; then
_npm_completion () {
local words cword
if type _get_comp_words_by_ref &>/dev/null; then
_get_comp_words_by_ref -n = -n @ -n : -w words -i cword
else
cword="$COMP_CWORD"
words=("${COMP_WORDS[@]}")
fi
local si="$IFS"
IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \
COMP_LINE="$COMP_LINE" \
COMP_POINT="$COMP_POINT" \
npm completion -- "${words[@]}" \
2>/dev/null)) || return $?
IFS="$si"
if type __ltrim_colon_completions &>/dev/null; then
__ltrim_colon_completions "${words[cword]}"
fi
}
complete -o default -F _npm_completion npm
elif type compdef &>/dev/null; then
_npm_completion() {
local si=$IFS
compadd -- $(COMP_CWORD=$((CURRENT-1)) \
COMP_LINE=$BUFFER \
COMP_POINT=0 \
npm completion -- "${words[@]}" \
2>/dev/null)
IFS=$si
}
compdef _npm_completion npm
elif type compctl &>/dev/null; then
_npm_completion () {
local cword line point words si
read -Ac words
read -cn cword
let cword-=1
read -l line
read -ln point
si="$IFS"
IFS=$'\n' reply=($(COMP_CWORD="$cword" \
COMP_LINE="$line" \
COMP_POINT="$point" \
npm completion -- "${words[@]}" \
2>/dev/null)) || return $?
IFS="$si"
}
compctl -K _npm_completion npm
fi
# NVM #
#
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
export NODE_EXTRA_CA_CERTS="/Users/fharper/Documents/configs/charles-ssl-proxying-certificate.pem"
# Aliases #
#
alias rm=trash
# CD into newly cloned folder automatically #
#
git()
{
if [ "$1" = clone ] ; then
/usr/local/bin/git "$@" && cd $(basename $_ .git)
echo 'Changing directory to repo folder...'
else
/usr/local/bin/git "$@"
fi
}
# Z #
#
. /usr/local/etc/profile.d/z.sh
#JENV
eval "$(jenv init -)"
eval "$(pyenv init -)"
#Terraform automcompletion
complete -C /usr/local/bin/terraform terraform
#Kubernetes autocompletion
source <(kubectl completion bash)