forked from rmm5t/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 15
/
bashrc
299 lines (243 loc) · 8.44 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
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
############################################################
if [ -e /etc/bashrc ] ; then
. /etc/bashrc
fi
############################################################
## PATH
############################################################
if [ -d ~/bin ] ; then
PATH="${HOME}/bin:${PATH}"
fi
if [ -d /usr/local/bin ] ; then
PATH="/usr/local/bin:${PATH}"
fi
if [ -d /usr/local/sbin ] ; then
PATH="${PATH}:/usr/local/sbin"
fi
if [ -d $HOME/dotfiles/bin ] ; then
PATH="${PATH}:$HOME/dotfiles/bin"
fi
if [ -d $HOME/Library/Python/3.7/bin ] ; then
PATH="${PATH}:$HOME/Library/Python/3.7/bin"
fi
export HOMEBREW_PREFIX="/opt/homebrew";
export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
export HOMEBREW_REPOSITORY="/opt/homebrew";
export HOMEBREW_SHELLENV_PREFIX="/opt/homebrew";
export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:";
export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";
# rbenv
if [ `which rbenv 2> /dev/null` ]; then
eval "$(rbenv init -)"
fi
# Node Package Manager
# if [ -d /usr/local/share/npm/bin ] ; then
# NODE_PATH="/usr/local/lib/node"
# PATH="${PATH}:/usr/local/share/npm/bin"
# fi
PATH=./bin:${PATH}
PATH=.:${PATH}
############################################################
## MANPATH
############################################################
if [ -d /usr/local/man ] ; then
MANPATH="/usr/local/man:${MANPATH}"
fi
############################################################
## RVM
############################################################
# if [[ -s ~/.rvm/scripts/rvm ]] ; then source ~/.rvm/scripts/rvm ; fi
############################################################
## Terminal behavior
############################################################
# Change the window title of X terminals
case $TERM in
xterm*|rxvt|Eterm|eterm)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
;;
screen)
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
;;
esac
# Show the git branch and dirty state in the prompt.
# Borrowed from: http://henrik.nyh.se/2008/12/git-dirty-prompt
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\(\1$(parse_git_dirty)\)/"
}
if [ `which git` ]; then
function git_prompt {
parse_git_branch
}
else
function git_prompt {
echo ""
}
fi
if [ `which rvm-prompt` ]; then
function rvm_prompt {
echo "($(rvm-prompt v g))"
}
else
function rvm_prompt {
echo ""
}
fi
# Do not set PS1 for dumb terminals
if [ "$TERM" != 'dumb' ] && [ -n "$BASH" ]; then
# export PS1='\[\033[32m\]\n[\s: \w] $(rvm_prompt) $(git_prompt)\n\[\033[31m\][\u@\h]\$ \[\033[00m\]'
# export PS1='\[\033[32m\]\n[\s: \w] $(git_prompt)\n\[\033[31m\][\u@\h]\$ \[\033[00m\]'
export PS1='\[\033[32m\]\n[\s: \w]\n\[\033[31m\][\u@\h]\$ \[\033[00m\]'
fi
############################################################
## Optional shell behavior
############################################################
shopt -s cdspell
shopt -s extglob
shopt -s checkwinsize
export PAGER="less"
export EDITOR="nvim"
############################################################
## History
############################################################
# When you exit a shell, the history from that session is appended to
# ~/.bash_history. Without this, you might very well lose the history of entire
# sessions (weird that this is not enabled by default).
shopt -s histappend
export HISTIGNORE="&:pwd:ls:ll:lal:[bf]g:exit:rm*:sudo rm*"
# remove duplicates from the history (when a new item is added)
export HISTCONTROL=erasedups
# increase the default size from only 1,000 items
export HISTSIZE=10000
############################################################
## Bash Completion, if available
############################################################
if [ -f /opt/local/etc/bash_completion ]; then
. /opt/local/etc/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
elif [ -f /etc/profile.d/bash_completion ]; then
. /etc/profile.d/bash_completion
elif [ -f /usr/local/etc/bash_completion.d ]; then
. /etc/profile.d/bash_completion
fi
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
# http://onrails.org/articles/2006/11/17/rake-command-completion-using-rake
if [ -f ~/bin/rake_completion ]; then
complete -C ~/bin/rake_completion -o default rake
fi
if [ -f ~/bin/thor_completion ]; then
. ~/bin/thor_completion
fi
if [ -f ~/bin/git_completion ]; then
. ~/bin/git_completion
fi
if [ -f ~/dotfiles/tmuxinator.bash ]; then
. ~/dotfiles/tmuxinator.bash
fi
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
function _ssh_completion() {
perl -ne 'print "$1 " if /^Host (.+)$/' ~/.ssh/config
}
complete -W "$(_ssh_completion)" ssh
# if [ -f ~/.rbenv/completions/rbenv.bash ]; then
# . ~/.rbenv/completions/rbenv.bash
# fi
############################################################
## Other
############################################################
source $HOMEBREW_PREFIX/etc/bash_completion.d/cdargs-bash.sh
if [[ "$USER" == '' ]]; then
# mainly for cygwin terminals. set USER env var if not already set
USER=$USERNAME
fi
############################################################
## Aliases
############################################################
if [ -e ~/.bash_aliases ] ; then
. ~/.bash_aliases
fi
############################################################
set -o emacs
function git_remote_branch_report {
if [ $1 ]; then
for k in `git branch -r | sed "s/ ->.*//"`;do echo -e `git log -1 --pretty=format:"%Cgreen%ci^%Cblue%cr^%Cred%an^%Creset^" "$k"`\\t"$k";done | sort -r | grep -i $1 | column -t -s^
else
for k in `git branch -r | sed "s/ ->.*//"`;do echo -e `git log -1 --pretty=format:"%Cgreen%ci^%Cblue%cr^%Cred%an^%Creset^" "$k"`\\t"$k";done | sort -r | column -t -s^
fi
}
function git_remote_branch_kill_by_author {
if [ $1 ]; then
read -r -d '' RUBY <<-'EOS'
$remove_remaining = false
$commands = []
def remove(remote_ref)
$commands << "git push origin :#{remote_ref}"
end
puts "Reading branches for #{ARGV[0]}..."
lines = %x(for k in `git branch -r | sed "s/ ->.*//"`; do echo `git log -1 --pretty=format:"%Cgreen%ci^%Cblue%cr^%Cred%an^%Creset^" "$k"` "$k"; done | sort -r | grep -i #{ARGV[0]}).split("\n")
puts "Got #{lines.size} refs.\n"
lines.each do |l|
parts = l.split(/\s*\^\s*/)
remote_ref = parts[-1].gsub(/origin\//, '')
print parts.join(" ")
if $remove_remaining
puts
remove remote_ref
else
print " Remove? (y/n/a): "
input = STDIN.gets.chomp
if input == "a"
puts "Removing remaining!"
$remove_remaining = true
remove(remote_ref)
elsif input == "y"
remove(remote_ref)
end
end
end
puts "Please wait while the branches are deleted..."
$commands.each { |c| puts c; system(c) }
puts "Done."
EOS
echo "$RUBY" > /tmp/_grbkba.rb
ruby /tmp/_grbkba.rb $1
else
echo Must provide name of author to grep on.
fi
}
function pairwith {
other="$*"
if [ "$other" ]; then
if [ "$other" == "self" ]; then
unset GIT_AUTHOR_NAME
echo Pairing with self... ಠ_ಠ
else
if [[ $other =~ , ]]; then
other="$other,"
fi
export GIT_AUTHOR_NAME="$other & Garvin"
echo $other > ~/.last_pairwith
echo Committing as ${GIT_AUTHOR_NAME}
fi
else
other=$(cat ~/.last_pairwith)
export GIT_AUTHOR_NAME="${other} & Garvin"
echo Committing as ${GIT_AUTHOR_NAME}
fi
}
# kill by name - from Matt Swasey
function gkill () {
pname=$1
formatted_pname="[${pname:0:1}]${pname:1}"
kill -9 $(ps aux | grep $formatted_pname | awk '{print $2}')
}
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
## folder /opt/homebrew contains Homebrew for arm64 #m1_homebrew-arm64
[[ $(arch) == "arm64" ]] && export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH" #m1_homebrew-arm64
[[ $(arch) == "x86_64" ]] && export PATH="/usr/local/Homebrew/bin:/usr/local/Homebrew/sbin:$PATH"
alias ibrew='arch --x86_64 /usr/local/Homebrew/bin/brew'