-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbash_profile
executable file
·366 lines (298 loc) · 13.8 KB
/
bash_profile
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
#!/usr/bin/env bash
echo " -----------------------------------------------------------"
###
# vim related
#
set -o vi # go into vi mode on the shell!!!
alias v="mvim --remote-silent "
alias upgrade_neovim=" workon neovim3 \
&& pip install --upgrade pynvim pylama_pylint pylama \
&& deactivate \
&& npm -g update neovim \
&& brew unlink neovim \
&& brew install --HEAD neovim"
alias upgrade_submodules='(cd ~/.dotfiles && git submodule update --merge --remote)'
alias vim='nvim'
alias vi='nvim'
alias git_neo_log='git_log --first-parent $(nvim --version | grep commit | cut -d" " -f2)..'
export EDITOR='nvim'
export MANPAGER="nvim -c 'set ft=man' -"
###
# brew installed utils
export PATH="$(brew --prefix coreutils)/libexec/gnubin:/usr/local/opt/findutils/libexec/gnubin:/usr/local/opt/grep/libexec/gnubin:/usr/local/opt/gnu-sed/libexec/gnubin:/usr/local/opt/gnu-tar/libexec/gnubin:$PATH"
export MANPATH="$(brew --prefix coreutils)/libexec/gnuman:$MANPATH"
# useful shortcuts
alias ..="cd .."
alias ...="cd ../.."
alias ..3="cd ../../.."
alias ..4="cd ../../../.."
# cd into whatever is the forefront Finder window.
cdf() { # short for cdfinder
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')" || return
}
alias ld="ls --color -lhA | grep '^d'"
alias ll="ls --color -lhF"
alias lla="ls --color -lhFA"
alias ls="ls --color"
alias bin="cd ~/bin"
alias dev="cd ~/Dev"
alias grep="grep --color=always -i "
# IP addresses
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="ipconfig getifaddr en1"
alias myip="ifconfig | grep 'inet ' | grep -v 127.0.0.1 | awk '{print \$2}'"
alias show_routes="netstat -rn"
# dev
alias apache_start="sudo apachectl -k start"
alias apache_restart="sudo apachectl -k restart"
alias apache_stop="sudo apachectl -k stop"
alias apache_conf="cd /etc/apache2/"
alias apache_log="cd /var/log/apache2/"
# homebrew
alias update_brew="brew update && brew outdated"
alias upgrade_brew="brew upgrade && brew outdated"
alias brew_desc="brew desc"
alias brew_cask="brew cask"
alias brew_formulas_that_depend_on="brew uses --recursive "
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
# enable bash compleation
#export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
# source kubectl and terraform bash completion
source <(kubectl completion bash)
which terraform-docs > /dev/null && source <(terraform-docs completion bash)
complete -C /usr/local/bin/terraform terraform
#
# python
#
export PATH="/usr/local/opt/python/libexec/bin:$HOME/Library/Python/3.9/bin:$PATH"
alias upgrade_pip3=" pip3 install --upgrade setuptools wheel \
&& pip3 install --upgrade pip \
&& pip3 install --upgrade virtualenv virtualenvwrapper \
&& for pkg in \$(pip3 list --outdated 2> /dev/null | tail -n +3 | awk '{ print \$1 }' | grep -v \"^pip3\\\$\"); do pip3 install -U \$pkg; done"
alias update_pip3="pip3 list --outdated"
# Setup virtual env
export WORKON_HOME=~/work/virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
# For installing dependencies
export LDFLAGS="$LDFLAGS -L/usr/local/opt/libgeoip/lib/ -L/usr/local/opt/openssl/lib -L/usr/local/opt/libxml2/lib -L$(brew info libmemcached | grep --color=none "\*$" | awk '{ print $1 }')/lib/"
export CPPFLAGS="$CPPFLAGS -I/usr/local/include/ -I/usr/local/opt/openssl/include -I/usr/local/opt/libxml2/include/libxml2/ -I$(brew info libmemcached | grep --color=none "\*$" | awk '{ print $1 }')/include/"
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
export PYCURL_SSL_LIBRARY=openssl
#
# git
#
alias git_bad_files='find . -name ".DS_Store" -or -name "Thumbs.db"'
alias git_log="git log --graph --pretty=format:'%Cred%h%Creset - %s %Cgreen(%cr)%Creset by %C(bold blue)%an%C(yellow)%d%Creset' --abbrev-commit --date=relative" # add --all to see all branches and not only the checkedout branch
alias git_log_all="git_log --branches --remotes --tags --decorate"
alias git_lastest_branches="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"
alias gp="git pull --rebase=merges"
alias gpush="git push --set-upstream origin HEAD" # Push current branch to origin with same branch name and set as tracking branch
alias gf="git fetch --all && git fetch --tags --force"
alias gs="git status"
alias gde="git diff --ignore-space-at-eol -b -w --ignore-blank-lines"
alias gd="gde --no-ext-diff"
alias gdo="gd origin/\$(git rev-parse --abbrev-ref HEAD)..HEAD"
gc() {
local BRANCH
# Interactivly choose a branch to checkout
BRANCH="$(git branch -a | fzf --ansi | sed -e "s#^\s*remotes/[^/]*/##")"
# Remove leading and trailing spaces
BRANCH="$(echo -e "${BRANCH}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
git checkout "$BRANCH"
# Setup remote tracking if it isn't yet setup
if [[ ! $(git rev-parse --symbolic-full-name --abbrev-ref "@{u}" 2> /dev/null) ]]; then
git branch --set-upstream-to="origin/$BRANCH" "$BRANCH"
fi
}
alias gc-='git checkout -'
alias gcd='git checkout develop'
alias gcm='git checkout master'
alias gcm-ec='git checkout master-ec'
alias git_cherrypick='git cherry-pick --signoff -x'
alias git_commit_files="git diff-tree --no-commit-id --name-status -r"
# gl - git commit browser (enter for show, ctrl-d for diff, ` toggles sort)
# TODO: Add options to seatch all branchs and exact seatch
gl() {
local out shas sha q k
while out=$(
git log --graph \
--pretty=format:'%Cred%h%Creset - %s %Cgreen(%cr)%Creset by %C(bold blue)%an%C(yellow)%d%Creset' \
--abbrev-commit --date=relative --color=always "$@" |
fzf --ansi --multi --no-sort --reverse --query="$q" \
--print-query --expect=ctrl-d --toggle-sort=\`); do
q=$(head -1 <<< "$out")
k=$(head -2 <<< "$out" | tail -1)
shas=$(sed '1,2d;s/^[^a-z0-9]*//;/^$/d' <<< "$out" | awk '{print $1}')
[ -z "$shas" ] && continue
if [ "$k" = ctrl-d ]; then
git diff --no-ext-diff --color=always --ignore-space-at-eol -b -w --ignore-blank-lines "$shas" |
diff-so-fancy |
less --tabs=1,5 -R
else
for sha in $shas; do
git show --color=always "$sha" | diff-so-fancy | less --tabs=1,5 -R
done
fi
done
}
alias glo='gl origin/$(git rev-parse --abbrev-ref HEAD)'
alias grh='git reset --hard origin/$(git rev-parse --abbrev-ref HEAD)'
# rake
alias rake_bower_install="rake bower:dsl:install"
# autojump
[ -f "$(brew --prefix)/etc/profile.d/autojump.sh" ] && . "$(brew --prefix)/etc/profile.d/autojump.sh"
# fzf #
export FZF_COMPLETION_TRIGGER=',,'
export FZF_COMPLETION_OPTS='-m --ansi'
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
# cheat
export CHEATCOLORS=true # add colores to cheat
########
# node #
########
alias node_list='npm -g list --depth=0'
export PATH="$HOME/bin:/usr/local/share/npm/bin:$PATH"
alias update_project_node="npm outdated --quiet --depth=0"
alias update_node="update_project_node --global"
alias upgrade_project_node="npm update"
alias upgrade_node="nvm install node --latest-npm && ~/.dotfiles/setup-scripts/Nodefile && upgrade_project_node --global"
# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$(brew --prefix)/opt/nvm/nvm.sh" ] && source "$(brew --prefix)/opt/nvm/nvm.sh"
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && source "/usr/local/opt/nvm/etc/bash_completion.d/nvm"
# add gulp completion
eval "$(gulp --completion=bash)"
####################
# RVM, Ruby, Rails #
####################
alias upgrade_rvm="rvm get stable && rvm requirements && rvm reload"
alias rvm_cheatsheat="start http://cheat.errtheblog.com/s/rvm"
alias rvm_known_rubys="rvm list known"
alias rc="rails console --sandbox"
alias gem_docs="yard server -g"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
# RVM bash completion
[[ -r "$HOME/.rvm/scripts/completion" ]] && source "$HOME/.rvm/scripts/completion"
# Perl
eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib=$HOME/perl5)"
############
# win apps #
############
alias wine-heidisql="wine 'C:\Program Files\HeidiSQL\heidisql.exe' &"
alias wine-BC="wine start /UNIX ~/.wine/drive_c/Program\ Files/Beyond\ Compare\ 3/BCompare.exe &"
alias wine-ie8="wine 'C:\Program Files\Internet Explorer\iexplore' &"
alias wine-toad="WINEPREFIX='$HOME/.wine32' WINEARCH='win32' wine 'C:\\Program Files\Quest Software\Toad for MySQL Freeware 7.3\toad.exe'"
alias wine-npp="wine 'C:\Program Files\Notepad++\notepad++.exe' &"
# Old:
# optional wine dependencies: brew install libntlm mpg123 samba
# run as 32 bit for dotnet35sp1: export WINEPREFIX="$HOME/.wine32"; export WINEARCH='win32'; winecfg
# install dotnet35sp1: winetricks -q msxml6 mfc42 gdiplus corefonts # not this dotnet35sp1
# export WINEDLLOVERRIDES=ngen.exe,mscorsvw.exe=b
# wine ~/Downloads/dotnetfx35setup.exe
# wineboot --update
# wine /Users/simonweil/Downloads/Quest_Toad-for-MySQL-Freeware_63.exe
# New:
# run as 32 bit for dotnet35sp1: WINEPREFIX="$HOME/.wine32" WINEARCH='win32' winecfg
# WINEPREFIX="$HOME/.wine32" WINEARCH='win32' winetricks dotnet40
# WINEPREFIX="$HOME/.wine32" WINEARCH='win32' wine ~/Downloads/ToadforMySQL_Freeware_7.3.1.3290.exe
###########
# History #
###########
# Larger bash history (allow 32³ entries; default is 500)
export HISTSIZE=32768
export HISTFILESIZE=$HISTSIZE
export HISTCONTROL=ignoredups
# timestamps for bash history. www.debian-administration.org/users/rossen/weblog/1
# saved for later analysis
export HISTTIMEFORMAT='%F %T '
# Make some commands not show up in history
export HISTIGNORE="ls:cd:cd -:pwd;exit:man *:history:date:* --help"
#######
# OSX #
#######
# Open any file in MacOS Quicklook Preview
ql () { qlmanage -p "$*" >& /dev/null & }
####################
# general settings #
####################
export LC_ALL='en_US.UTF-8'
export LANG='en_US.UTF-8'
function upgrade_say {
echo -e "\n-----------\nUpgrade $1:\n-----------"
}
alias update_macos="mas outdated"
function upgrade_macos {
if command -v xcodebuild > /dev/null; then
XCODE_SAVE_VERSION="$(xcodebuild -version | grep --color=none Xcode)"
fi
mas upgrade
if [[ "X$XCODE_SAVE_VERSION" != "X" && "$XCODE_SAVE_VERSION" != "$(xcodebuild -version | grep --color=none Xcode)" ]]; then
sudo xcodebuild -license accept
else
echo "Xcode not upgraded"
fi
unset XCODE_SAVE_VERSION
}
alias update_all="update_node; update_pip3 && update_macos && update_brew && echo -e \"\$(date)\\n\""
alias upgrade_all=" upgrade_say 'MAC' && upgrade_macos \
&& upgrade_say 'node' && upgrade_node \
&& upgrade_say 'Brew' && upgrade_brew \
&& upgrade_say 'pip3' && upgrade_pip3 \
&& source ~/.dotfiles/setup-scripts/Pipfile \
&& upgrade_say 'neovim' && upgrade_neovim \
&& upgrade_say 'RVM' && upgrade_rvm \
&& upgrade_say 'Dotfiles (all submodules)' && upgrade_submodules \
&& echo 'Done upgrading.'"
alias update_project="update_node_project && rake bower:list && bundle outdated"
# http://www.kirsle.net/wizards/ps1.html
# https://wiki.archlinux.org/index.php/Color_Bash_Prompt
#export PS1="\[$(tput setaf 6)\]\u\[$(tput setaf 3)\]:\[$(tput setaf 6)\]\w\[$(tput setaf 2)\]\$(branch=\`git branch 2> /dev/null | grep '^*' | cut -c3-\`; if [[ \"\$branch\" != \"\" ]]; then echo \" (\$branch) >\" ; fi)\[$(tput setaf 3)\]> \[$(tput sgr0)\]"
export CLICOLOR=""
# Add all private configuration
[[ -f ~/.dotfiles/bash_profile.private ]] && source ~/.dotfiles/bash_profile.private
if [ -f $(brew --prefix)/share/liquidprompt ]; then
. $(brew --prefix)/share/liquidprompt
fi
# setup brew command-not-found
if brew command command-not-found-init > /dev/null 2>&1; then
eval "$(brew command-not-found-init)"
fi
# Set ls colors (update from https://github.com/trapd00r/LS_COLORS)
# Another theme is: https://github.com/seebi/dircolors-solarized
eval $(dircolors -b $HOME/.dotfiles/non-packaged-repos/LS_COLORS/LS_COLORS)
# Another option:
# http://linux-sxs.org/housekeeping/lscolors.html
# Marker - for command line bookmarks
# https://github.com/pindexis/marker - clone the repo when iTerm 2.9 is released
#[[ -s "$HOME/.local/share/marker/marker.sh" ]] && source "$HOME/.local/share/marker/marker.sh"
echo " - Enable marker"
echo "Check: https://starship.rs/ as replacement for liquidprompt"
echo "Check: git-delta for git highlighting+"
##########################
# Other general settings #
##########################
# do not update brew every time brew command is used and don't autoupgrade on install
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_INSTALL_UPGRADE=1
export DISABLE_AUTO_TITLE=true # for tmux titles
alias tmux_attach="tmux -CC attach"
[ -r "$HOME/.smartcd_config" ] && ( [ -n $BASH_VERSION ] || [ -n $ZSH_VERSION ] ) && source ~/.smartcd_config
alias aws-whoami='aws sts get-caller-identity'
aws-ssh() {
local save_profile="$AWS_PROFILE"
if [[ "$1" != "" ]]; then
export AWS_PROFILE="$1"
else
unset AWS_PROFILE
fi
aws ssm start-session --target "$(aws ec2 describe-instances --query "Reservations[].Instances[].[InstanceId,InstanceType,Tags[?Key==\`Name\`]|[0].Value]" --output json | jq -r ".[]|@tsv" | fzf | cut -f1)"
if [[ $save_profile != "" ]]; then
export AWS_PROFILE="$save_profile"
else
unset AWS_PROFILE
fi
}
export PATH=".:$PATH"
echo " -----------------------------------------------------------"
source "$HOME/.config/broot/launcher/bash/br"