-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbashrc
More file actions
265 lines (221 loc) · 8.17 KB
/
bashrc
File metadata and controls
265 lines (221 loc) · 8.17 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
# System information
OS=$(uname -s)
# Shortcuts
if [ "$OS" = "Darwin" ]; then
alias brclean="brew cleanup --force -s"
alias brup="brew update && brew upgrade"
alias ls="ls -hGl" # h: human-readable size; l: long; G: color files and folders`
elif [ "$OS" = "Linux" ]; then
alias apt-get="sudo apt-get -y"
alias aptclean="apt-get autoremove && apt-get clean"
alias aptup="sudo apt-get -y update && sudo apt-get -y upgrade"
alias ls="ls -hl --color" # h: human-readable size; l: long; color: color files and folders`
alias pacman="sudo pacman"
fi
export PAGER="less -FRX"
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias :q="exit" # Vim is in
alias :qa!="tmux kill-session"
alias :qa="echo 'Are you sure? (add ! to quit)'"
alias ag="ag -C3 --pager \"$PAGER\""
alias apmi="apm install --packages-file $HOME/.atom/packages.txt"
alias autocop="git d origin/master --name-only | xargs bundle exec rubocop -a"
alias back="cd -"
alias be="bundle exec"
alias bs="bin/spring"
alias cp="cp -R"
alias de="docker exec -it"
alias df="df -H"
alias diff="colordiff"
alias dig="dig +noall +answer"
# alias docker="open -gja Docker && while ! docker system info > /dev/null 2>&1; do sleep 1; done && docker"
alias dotfiles="cd ~/dotfiles"
alias ecrlogin='$(aws ecr get-login --no-include-email)'
alias emptytrash="`which rm` -rf ~/.Trash/*"
alias getkey="gpg --keyserver pgp.mit.edu --recv-key"
alias gitignore="git status --ignored --porcelain | sed -ne '/^!! */s///p'"
alias haste="haste | pbcopy"
alias pr="hub pull-request -o"
alias js="node"
alias kc="kubectl"
alias ke="kubectl exec -it"
alias la="ls -a" # a: hidden files
alias less="$PAGER" # tame less with colors
if [ "$OS" = "Darwin" ]; then
alias linux="container run -it --rm debian:stable-slim"
elif [ "$OS" = "Linux" ]; then
alias linux="docker run -it --entrypoint bash debian:stable-slim"
fi
alias lstree="tree" # It's a shortcut to save me from googling it every time.
alias mkdir="mkdir -p"
alias myip6="curl -L https://ipv6.icanhazip.com"
alias myip="curl -L https://ipv4.icanhazip.com"
alias oblique="fortune oblique"
alias pgp="gpg"
alias reboot="sudo reboot"
alias rebundle="rm Gemfile.dev.lock && cp Gemfile.lock Gemfile.dev.lock && bundle"
alias recd="cd .. && cd -"
alias reset="source $HOME/.bashrc && clear"
alias rg="rg -i"
alias rgf="rg --files | rg"
alias rm="rm -rf"
alias rmswp="find . -name \"*.swp\" -exec rm {} \; && rm ~/.local/share/nvim/swap/*.swp"
alias rr="rbenv rehash"
alias rs="rbenv sudo"
alias rtfm="man"
alias scp="rsync -Phae ssh"
alias shutdown="sudo shutdown -h now"
alias sk9="sudo kill -9"
alias ss="spring stop"
alias ssh="ssh -AC" # A: agent key forwarding. C: compression.
alias tf="terraform"
alias vac="source ENV/bin/activate"
alias vi="nvim"
alias vim="nvim"
shopt -s autocd # Change to a directory without "cd"
shopt -s globstar # Enable recursive globstar
function dockerclean () {
echo "Killing containers:"
docker ps -q | xargs docker kill
echo "Containers:"
docker container ls -aq | xargs docker rm
echo "Volumes:"
docker volume ls -q | xargs docker volume rm
echo "Images:"
docker image ls -q | xargs docker image rm -f
}
function du () {
ncdu "$@"
}
function agignore () {
gitignore > ~/.agignore
}
function psgrep () {
ps ax | rg $1
}
function psid() {
psgrep $1 | awk '{print $1}'
}
function pskill() {
psid $1 | xargs kill
}
function redcat () {
cat $@ | grep -Eo $'\e\\[31m[^\e]*\e\\[[03]?m'
}
function redless () {
redcat $@ | less
}
function repeatUntilSuccessful() {
$@; while [ $? -ne 0 ]; do $@; done
}
# rm moves files to trash
function trash () {
local path
for path in "$@"; do
# ignore any arguments
if [[ "$path" = -* ]]; then :
else
local dst=${path##*/}
# append the time if necessary
while [ -e ~/.Trash/"$dst" ]; do
dst="$dst "$(date +%H-%M-%S)
done
mv "$path" ~/.Trash/"$dst"
fi
done
}
function cur () {
curl -L "$@" | tar xf -
}
# check whether a command exists
commandExists () {
command -v $@ >/dev/null 2>&1 || { echo >&2 "I require $@ but it's not installed."; return 1; }
}
# Environment
export VISUAL='nvim'
export GIT_EDITOR="$VISUAL"
export EDITOR="$VISUAL"
export PATH="/usr/local/opt/llvm/bin:$HOME/.config/yarn/global/node_modules/.bin:$HOME/.rbenv/bin:$HOME/bin:/usr/local/opt/python@2/bin:/usr/local/opt/python/libexec/bin:/usr/local/bin:/usr/local/sbin:/usr/local/share/npm/bin:/usr/local/mysql/bin:/usr/local/go/bin:$HOME/.cabal/bin:/usr/local/opt/node@14/bin:$HOME/go/bin:$PATH"
eval "$(/opt/homebrew/bin/brew shellenv)"
export GOPATH=~/Projects/code/go
GIT_PS1_SHOWDIRTYSTATE=1 # Indicate changed files
# Mac/Linux PS1s that account for different hostname commands
if [ "$OS" = "Darwin" ]; then
host=$(hostname -s)
elif [ "$OS" = "Linux" ]; then
host=$(hostname)
fi
export PS1='\[\e[0;33m\]$(date "+%Y-%m-%d %r") \[\e[0;32m\]$host: $([ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") "$PWD")\[\e[0;36m\]\W\[\e[0;35m\]$(__git_ps1 " ± %s")\[\e[m\] \n\[\e[0;38;05;202m\]\$\[\e[m\] ' # The best prompt ever, with colors and wd's git branch
export HISTCONTROL=ignoredups:erasedups # Keeps history concise
# Gives history more room
export HISTFILESIZE=4096
export HISTSIZE=4096
# bash completion
if [ "$OS" = "Darwin" ] && [[ -r "/opt/homebrew/etc/profile.d/bash_completion.sh" ]]; then
. "/opt/homebrew/etc/profile.d/bash_completion.sh"
elif [ "$OS" = "Linux" ] && [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/completions/git
. /usr/share/git/git-prompt.sh # for __git_ps1
fi
. /opt/homebrew/opt/asdf/libexec/asdf.sh
# SSH keychain
export KEYCHAIN="keychain"
export KEYCHAIN_ARGS="--quiet --eval --agents ssh"
export KEYFILE="id_ed25519"
if [ "$OS" = "Darwin" ]; then
export KEYCHAIN_ARGS="$KEYCHAIN_ARGS --inherit any"
fi
keys () {
commandExists $KEYCHAIN && eval "$($KEYCHAIN $KEYCHAIN_ARGS $KEYFILE)"
}
. ~/.bashrc_p
base16 () {
if [ $TERM != "dumb" ]; then
# Base16 Shell
BASE16_SCHEME="bright"
BASE16_BACKGROUND=$(defaults read -g AppleInterfaceStyle 2>/dev/null | awk '{print tolower($0)}')
if [ -z $BASE16_BACKGROUND ]; then
BASE16_BACKGROUND="light"
fi
BASE16_SHELL="$HOME/.base16/base16-$BASE16_SCHEME.$BASE16_BACKGROUND.sh"
[[ -s $BASE16_SHELL ]] && . $BASE16_SHELL
fi
}
base16
export CLOUDSDK_PYTHON=$(which python3)
export CLOUDSDK_GSUTIL_PYTHON=$CLOUDSDK_PYTHON
# The next line updates PATH for the Google Cloud SDK.
if [ -f "$HOME/google-cloud-sdk/path.bash.inc" ]; then . "$HOME/google-cloud-sdk/path.bash.inc"; fi
# The next line enables shell command completion for gcloud.
if [ -f "$HOME/google-cloud-sdk/completion.bash.inc" ]; then . "$HOME/google-cloud-sdk/completion.bash.inc"; fi
alias gam="$HOME/bin/gam/gam"
export PATH="$HOME/.cargo/bin:$PATH"
awsp () {
if [[ -f ~/.aws/credentials && -n "${1}" ]]; then
local aws_access_key_id=$(awk '/^\[profile '"${1}"'\]/{f=1} f==1&&/aws_access_key_id/{print $3;exit}' ~/.aws/credentials);
local aws_secret_access_key=$(awk '/^\[profile '"${1}"'\]/{f=1} f==1&&/aws_secret_access_key/{print $3;exit}' ~/.aws/credentials);
local aws_default_region=$(awk '/^\[profile '"${1}"'\]/{f=1} f==1&&/region/{print $3;exit}' ~/.aws/config);
local aws_region=$(awk '/^\[profile '"${1}"'\]/{f=1} f==1&&/region/{print $3;exit}' ~/.aws/config);
if [[ -n "${aws_access_key_id}" && -n "${aws_secret_access_key}" ]]; then
export AWS_ACCESS_KEY_ID=${aws_access_key_id};
export AWS_SECRET_ACCESS_KEY=${aws_secret_access_key};
export AWS_DEFAULT_REGION=${aws_default_region};
export AWS_REGION=${aws_region};
export AWS_ACCOUNT=$(aws iam get-user --query 'User.[Arn]' --output text | cut -d: -f5);
export AWS_PROFILE=${1}
else
echo "Profile ${1} doesn't appear to be configured in ~/.aws/credentials" 1>&2;
fi;
else
echo "File ~/.aws/credentials don't exist || no profile given" 1>&2;
fi
}
oblique
complete -C /opt/homebrew/bin/terraform terraform
complete -C terraform tf
complete -C rsync scp
# [ -f ~/.fzf.bash ] && source ~/.fzf.bash
# source ~/.fzf-tab-completion/bash/fzf-bash-completion.sh
# bind -x '"\t": fzf_bash_completion'