-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc.symlink
205 lines (178 loc) · 5.14 KB
/
.bashrc.symlink
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
# Bash aliases
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# Bash completions
if type brew &> /dev/null; then
HOMEBREW_PREFIX="$(brew --prefix)"
if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then
source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
else
for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*; do
[[ -r $COMPLETION ]] && source "$COMPLETION"
done
fi
fi
if [[ -d $HOME/.bash_completion.d ]]; then
shopt -s extglob
for f in $HOME/.bash_completion.d/*; do
source $f
done
fi
# kitty auto-completion
source /dev/stdin <<< "$(kitty + complete setup bash)"
# vi-mode
set -o vi
bind -m vi-command ".":insert-last-argument
bind -m vi-insert "\C-l.":clear-screen
bind -m vi-insert "\C-a.":beginning-of-line
bind -m vi-insert "\C-e.":end-of-line
bind -m vi-insert "\C-w.":backward-kill-word
# Use https://starship.rs/ for my prompt
eval "$(starship init --print-full-init bash)"
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return ;;
esac
# pullify - add remote for pull reuqests
function pullify() {
git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'
}
## functions from http://code.toofishes.net/cgit/dan/configfiles.git/tree/bashrc
# sanitize - set file/directory owner and permissions to normal values (644/755)
# Usage: sanitize <file>
sanitize() {
chmod -R u=rwX,go=rX "$@"
chown -R ${USER}:${USER} "$@"
}
# psfind - shortcut for grepping a process name
# Usage: psfind <process name>
psfind() {
ps -ef | egrep "PID|$@"
}
# notes! from http://jasonwryan.com/post/1203000683/awk-notes
n() {
$EDITOR ~/.notes/"$*".txt
}
nls() {
tree -CR --noreport ~/.notes | awk '{ if (NF==1) print $1; else if (NF==2) print $2; else if (NF==3) print " "$3 }'
}
# bash vi editing mode
# from http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-sheet/
#set -o vi
#set editing-mode vi
#set keymap vi
# ^p check for partial match in history
bind -m vi-insert "\C-p":dynamic-complete-history
# ^n cycle through the list of partial matches
bind -m vi-insert "\C-n":menu-complete
export HISTFILESIZE=500000
export HISTSIZE=100000
export HISTIGNORE="&:[ ]*:exit"
shopt -s histappend
shopt -s cmdhist
export HISTTIMEFORMAT='%F %T '
# use ** to search any depth
if [[ $(uname) != Darwin ]]; then
shopt -s globstar
fi
shopt -s histverify
# convert cprofile output to something useful
function cprof2png() {
gprof2dot -f pstats $1 | dot -Tpng -o $1.png
}
function cprof2dot() {
gprof2dot -f pstats $1 > $1.dot
}
# human readable du -sh
function duf() {
du -sk "$@" | sort -n | while read size fname; do for unit in k M G T P E Z Y; do
if [ $size -lt 1024 ]; then
echo -e "${size}${unit}\t${fname}"
break
fi
size=$((size / 1024))
done; done
}
# List exposed ports on a Docker image/container
docker-ports() {
docker inspect --format='{{range $port, $_ := .Config.ExposedPorts}}{{$port}}{{"\n"}}{{end}}' $1 | cut -d "/" -f 1 -s
}
docker_nuke() {
docker rm -f $(docker ps -a -q)
docker rmi -f $(docker images -q)
}
# vex
function workon() {
vex $1
}
function mkvirtualenv() {
vex -m $@
}
function lsvirtualenv() {
\ls ~/.virtualenvs/
}
function rmvirtualenv() {
rm -rf ~/.virtualenvs/$1
}
function mktmpenv() {
vex -rm $@ tmp-$(date +%s)
}
# Don't install anything globally with pip
export PIP_REQUIRE_VIRTUALENV=true
# Use 'gpip' to upgrade pip/virtualenv/etc.
gpip() {
PIP_REQUIRE_VIRTUALENV="" pip "$@"
}
gpip3() {
PIP_REQUIRE_VIRTUALENV="" pip3 "$@"
}
# AWS
unset_aws() {
for i in AWS_ACCESS_KEY_ID AWS_DEFAULT_REGION AWS_REGION AWS_SECRET_ACCESS_KEY AWS_SECURITY_TOKEN AWS_SESSION_TOKEN AWS_VAULT; do unset $i; done
}
function assume-aws() {
if grep -q "[okta]" ~/.aws/config; then
local AWS_CMD=aws-okta
else
local AWS_CMD=aws-vault
fi
unset_aws
eval $($AWS_CMD exec $@ -- env | grep -E "^AWS_" | sed -e "s/^/export\ /")
AWS_PAGER="" aws --output text --query Arn sts get-caller-identity
}
function aws-get-console-output() {
aws ec2 get-console-output --instance-id $1 | jq -r '.Output'
}
function aws-get-that-ip() {
AWS_PAGER="" aws ec2 describe-instances \
--filter Name=network-interface.addresses.private-ip-address,Values=$1 \
--query 'Reservations[*].Instances[*].{Instance:InstanceId,Name:Tags[?Key==`Name`]|[0].Value}' \
--output text
}
# vim-plug
function vim-plug-install() {
vim +"let g:plug_window='enew'" +PlugInstall
}
function vim-plug-update() {
vim +"let g:plug_window='enew'" +PlugUpgrade +PlugUpdate
}
function vim-plug-clean() {
vim +"let g:plug_window='enew'" +PlugClean
}
# fzf
export FZF_DEFAULT_COMMAND='fd --type f'
# Use fd (https://github.com/sharkdp/fd) instead of the default find
# command for listing path candidates.
# - The first argument to the function ($1) is the base path to start traversal
# - See the source code (completion.{bash,zsh}) for the details.
_fzf_compgen_path() {
fd --hidden --follow . "$1"
}
# Use fd to generate the list for directory completion
_fzf_compgen_dir() {
fd --type d --hidden --follow . "$1"
}
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
[ -f ~/.config/broot/launcher/bash/br ] && source ~/.config/broot/launcher/bash/br