Repository navigation
Expand file tree
/
Copy path.bashrc
More file actions
197 lines (161 loc) · 5.39 KB
/
Copy path.bashrc
File metadata and controls
197 lines (161 loc) · 5.39 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
##############################################
############## MINI PLUGIN SYSTEM ############
##############################################
shopt -s nullglob
for filename in ~/.config/custom_bash_scripts/*; do
source $filename
done
shopt -u nullglob
##############################################
############# OH MY BASH SETTINGS ############
##############################################
# Enable the subsequent settings only in interactive sessions
case $- in
*i*) ;;
*) return ;;
esac
export OSH="$HOME/.oh-my-bash"
OSH_THEME="font"
OMB_USE_SUDO=false
completions=(
git
composer
ssh
)
aliases=(
general
)
plugins=(
git
)
source "$OSH"/oh-my-bash.sh
##############################################
############### SHELL SETTINGS ###############
##############################################
# enable vi mode
set -o vi
bind "\C-p":previous-history
bind "\C-n":next-history
bind "\C-l":clear-screen
##############################################
############ ENVIRONMENT SETTINGS ############
##############################################
export EDITOR="nvim"
export XDG_CONFIG_HOME="$HOME/.config"
##############################################
################## ALIASES ###################
##############################################
# quick configs
alias v="nvim"
alias vim="nvim"
alias zshrc='"$EDITOR" ~/.zshrc'
alias i3conf='"$EDITOR" ~/.config/i3/config'
alias ed="nvim ~/projects/dotfiles"
alias l='ls -l'
alias la='ls -a'
alias lla='ls -la'
alias lt='ls --tree'
# git
alias gs='git status -u'
alias gd='git diff'
alias gdc='git diff --cached'
alias gdb='git diff development --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space --find-renames'
alias gcm='git commit -m'
alias gcma='git commit --amend'
alias gl="git log --graph --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short"
alias gaa='git add "*"'
alias gfa='git fetch --all'
alias gp='git pull'
alias pushnoci='git push -o integrations.skip_ci'
alias sbr='git branch --all | fzf | xargs git switch' # switch branch
# postgres stuff
alias pgl='python -m pgcli -U postgres -d' # followed by db_name
alias listdbs='python -m pgcli -U postgres -l'
# Remove the oh my bash update lock if it hangs again
alias fixomb='sudo touch /home/$USER/.oh-my-bash/log/update.lock && sudo rm -rf /home/$USER/.oh-my-bash/log/update.lock'
# program aliases
alias tf='terraform'
alias kc='kubectl'
##############################################
########## PROGRESSIVE ENHANCEMENT ###########
##############################################
if command -v lsd &>/dev/null; then
alias ls='lsd'
fi
# if command -v pyenv &>/dev/null; then
# pyenv init --install
# fi
if [ -f /usr/share/nvm/init-nvm.sh ]; then
source "/usr/share/nvm/init-nvm.sh"
fi
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
# fzf
# linux
[ -f /usr/share/fzf/key-bindings.bash ] && source /usr/share/fzf/key-bindings.bash
# mac
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
alias al='actionlint -shellcheck="" -config-file=$HOME/.config/actionlint-custom/config.yaml'
##############################################
############## CUSTOM FUNCTIONS ##############
##############################################
# Forcefully kill a process based a port it occupies
# Usage: portpkill <port>
function portpkill() {
ss_line=$(ss -lptn "sport = $1")
pid=$(echo $ss_line | awk -F'pid=' '{print $2}' | awk -F',' '{print $1}')
kill -9 $pid
}
# Git Push Upstream
# - Create a upstream branch for the currently checked out branch at the origin remote
# - Push the local changes to the upstream branch
function gpu {
branch_name=$(git rev-parse --abbrev-ref HEAD)
if [ $? -ne 0 ]; then
echo 'Failed to retrieve branch name. Potentially the command was executed outside a git repository'
exit 1
fi
git push --set-upstream origin "$branch_name"
}
# kube context
kctx() {
local ctx
ctx=$(kubectl config get-contexts -o name | fzf --prompt="Select k8s context: " --height=40% --reverse)
if [ -n "$ctx" ]; then
kubectl config use-context "$ctx"
else
echo "No context selected."
fi
}
# helper to quickly jump to certain git repos
pj() {
local dir
dir=$(find ~/projects -mindepth 1 -maxdepth 2 -type d \
-exec test -d '{}/.git' ';' -print -prune 2>/dev/null \
| fzf) || return
[ -n "$dir" ] && cd "$dir" && clear
}
##############################################
#################### MISC ####################
##############################################
# Colored man pages
export LESS_TERMCAP_mb=$'\e[1;31m' # begin bold
export LESS_TERMCAP_md=$'\e[1;33m' # begin blink
export LESS_TERMCAP_so=$'\e[01;44;37m' # begin reverse video
export LESS_TERMCAP_us=$'\e[01;37m' # begin underline
export LESS_TERMCAP_me=$'\e[0m' # reset bold/blink
export LESS_TERMCAP_se=$'\e[0m' # reset reverse video
export LESS_TERMCAP_ue=$'\e[0m' # reset underline
export GROFF_NO_SGR=1
export PATH="$PATH:/home/$USER/projects/scripts"
export PATH=$PATH:/home/$USER/go/bin
function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
function print_kube_secret() {
namespace="$1"
secret_name="$2"
kubectl -n "$namespace" get secret "$secret_name" -o go-template='{{range $k,$v := .data}}{{$k}}: {{$v | base64decode}}{{"\n"}}{{end}}'
}
function random_pw() {
LC_ALL=C tr -dc 'A-Za-z0-9!@#%&*_+=-' </dev/urandom | head -c 32; echo
}