-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot-bashrc
237 lines (186 loc) · 5.75 KB
/
dot-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
# shellcheck shell=bash
# From man 1 bash:
# When an interactive shell that is not a login shell is started, bash reads
# and executes commands from /etc/bash.bashrc and ~/.bashrc, if these
# files exist.
# shellcheck disable=SC1090
[[ -f ~/.bash_profile ]] && source ~/.bash_profile
#######################################
##
## Utility Functions
##
#######################################
stderr() {
echo -e "$*" >&2
}
stdout() {
echo -e "$*"
}
debug() {
test -n "${BASHRC_DEBUG}" && stderr "[DEBUG] ${FUNCNAME[1]}() ${*}"
}
#######################################
##
## Configuration
##
#######################################
## Bash
set -o vi
shopt -s \
checkwinsize \
histappend \
hostcomplete
umask 0027
# Default prompts
PS1='\n\W\$ '
export PS1
PS2="; "
export PS2
# History control
export HISTCONTROL=ignoredups:ignorespace
export HISTFILESIZE=2147483648
export HISTIGNORE="ls:cd:cd -:pwd:exit:date:pass *"
export HISTSIZE=2147483648
export HISTTIMEFORMAT="%Y-%m-%dT%H:%M:%S%z "
# Search path for the cd command
export CDPATH=".:~:~/src"
# General
export VISUAL=vim
# Environment Activations
# Starship - https://starship.rs/
# Intentionally loaded early
# shellcheck disable=SC1090
hash starship 2>/dev/null && eval "$(starship init bash)"
# Mise - https://mise.jdx.dev/
# Intentionally activated early so it can be a dependency. It has to be *after*
# the prompt is initialized though due to how it manipulates PATH.
# shellcheck disable=SC1090
hash mise 2>/dev/null && (
eval "$(mise activate bash)"
eval "$(mise completion bash)"
)
# Builtins
# shellcheck disable=SC1091
[[ -r /etc/bash_completion ]] && \
source /etc/bash_completion
# Bat - https://github.com/sharkdp/bat
hash bat 2>/dev/null && alias cat="bat"
# Exa - https://the.exa.website/
hash exa 2>/dev/null && alias ls="exa"
# Git - https://git-scm.com/
alias g="git"
alias ga="git add"
alias gb="git branch"
alias gc="git commit"
alias gca="git commit --all --message"
alias gcm="git commit --message"
alias gco="git checkout"
alias gcob="git checkout -b"
alias gd="git diff"
alias gdc="git diff --check"
alias gl="git log"
alias gld="git log --pretty=format:\"%h %ad %s\" --date=short--all"
alias glg="git log --graph --oneline --decorate --all"
alias gm="git merge"
alias gp="git pull"
alias gs="git status --branch"
# shellcheck disable=SC1091
[[ -r /usr/share/bash-completion/completions/git ]] && {
source /usr/share/bash-completion/completions/git
__git_complete g git
__git_complete ga git_add
__git_complete gb git_branch
__git_complete gc git_commit
__git_complete gca git_commit
__git_complete gcm git_commit
__git_complete gco git_checkout
__git_complete gco git_checkout
__git_complete gd git_diff
__git_complete gd git_diff
__git_complete gl git_log
__git_complete gl git_log
__git_complete gl git_log
__git_complete gm git_merge
__git_complete gp git_pull
__git_complete gs git_status
}
# Helm - https://helm.sh/docs/helm/helm_completion_bash/
# shellcheck disable=SC1090
hash helm 2>/dev/null && eval "$(helm completion bash)"
# Homebrew - https://docs.brew.sh/Homebrew-on-Linux
[[ -x ~linuxbrew/.linuxbrew/bin/brew ]] && \
eval "$(~linuxbrew/.linuxbrew/bin/brew shellenv)"
# Just - https://just.systems/
# shellcheck disable=SC1090
hash just 2>/dev/null && eval "$(just --completions bash)"
# Kind - https://kind.sigs.k8s.io/
# shellcheck disable=SC1090
hash kind 2>/dev/null && eval "$(kind completion bash)"
# Kubectl - https://kubernetes.io/docs/reference/kubectl/kubectl/
# shellcheck disable=SC1090
hash kubectl 2>/dev/null && eval "$(kubectl completion bash)"
# Pulumi - https://www.pulumi.com/
# shellcheck disable=SC1090
hash pulumi 2>/dev/null && eval "$(pulumi gen-completion bash)"
# SSH Agent
export SSH_ENV=~/.ssh/environment
# Prefer GPG SSH Agent
if grep '^enable-ssh-support$' ~/.gnupg/gpg-agent.conf &>/dev/null; then
GPG_TTY=$(tty)
export GPG_TTY
SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
export SSH_AUTH_SOCK
gpgconf --launch gpg-agent
else
# shellcheck disable=SC1090
test -r "${SSH_ENV}" && source "${SSH_ENV}"
if [[ "$(ps -q "${SSH_AGENT_PID}" -o comm=)" != "ssh-agent" ]]; then
ssh-agent -t $((60 * 60 * 6)) | head -n-1 > "${SSH_ENV}"
fi
fi
# Zellij - https://zellij.dev/
# shellcheck disable=SC1090
hash zellij 2>/dev/null && eval "$(zellij setup --generate-completion bash)"
# Misc.
alias cp="cp -i"
alias df="df -hP"
alias du="du -shx"
alias ll="ls -l"
alias fs="python -m SimpleHTTPServer"
alias mount="mount | column -t"
alias mv="mv -i"
alias path="printenv PATH | sed 's/:/\n/g'"
alias ping="ping -c 5 -W 5"
# Quickly copy public key
alias pubkey='cat ${HOME}/.ssh/*.pub | sort | uniq | xclip -selection clipboard | echo -e "\e[32m🛈\e[0m Public keys copied to clipboard"'
# From bash(1): If the last character of the alias value is a blank, then the
# next command word following the alias is also checked for alias expansion.
alias sudo='sudo '
# trash-cli - https://github.com/andreafrancia/trash-cli
hash trash 2>/dev/null && alias rm="trash"
alias update="sudo apt-get update && sudo apt-get upgrade && sudo apt-get clean && sudo apt-get autoremove"
# URL-encode strings
alias urlencode='python3 -c '\''import sys, urllib.parse; print(urllib.parse.quote_plus(str(" ".join(sys.argv[1:]))));'\'''
alias wget="wget -c"
alias zzz="systemctl suspend"
# bump_*
#
# $ echo 1.2.3 | bump_minor
# 1.3.3
# $ echo 1.2.3 | bump_z
# 1.2.4
bump_major() {
awk -F'.' '{print $1+1"."$2"."$3}'
}
alias bump_x=bump_major
bump_minor() {
awk -F'.' '{print $1"."$2+1"."$3}'
}
alias bump_y=bump_minor
bump_patch() {
awk -F'.' '{print $1"."$2"."$3+1}'
}
alias bump_z=bump_patch
# Include local, non-checked-in config/overrides
# shellcheck disable=SC1090
[[ -r ~/.local/config.bash ]] && source ~/.local/config.bash