-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
268 lines (217 loc) · 6.96 KB
/
zshrc
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
# pyenv
if [[ -d $HOME/.pyenv ]] ; then
# Add pyenv executable to PATH and enable shims
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/versions/3.9.6/bin:$PATH"
eval "$(pyenv init --path)"
# Load pyenv into the shell
eval "$(pyenv init -)"
fi
export EDITOR=$(which nvim)
export PATH=$PATH:$HOME/bin
export PATH=$PATH:$HOME/.local/bin
export KUBE_CONFIG_PATH=$HOME/.kube/config
# make fzf index hidden directories
export FZF_DEFAULT_COMMAND='fd --type f -H'
if [[ -f ~/.env ]] then
source ~/.env
fi
alias kibana="k port-forward -n kube-system service/kibana-logging 5601"
# -------------------------- ALIASES --------------------------------
# my darling boy
alias n='nvim'
# venv-related aliases
VENV_NAME="venv"
alias vnv="python3.10 -m venv $VENV_NAME \
&& source $VENV_NAME/bin/activate \
&& pip install --upgrade pip"
alias vnvr="vnv && pip install -r requirements.txt"
alias act="source $VENV_NAME/bin/activate"
# screen
alias ss="screen -d -r" # screen session
alias sn="screen -S" # screen new (session)
alias sl="screen -ls"
# terraform
alias tf="terraform"
# misc
alias nt="nvim -c \"terminal\""
alias temp="cd $(mktemp -d)"
# git
alias ggg="nvim ~/.oh-my-zsh/plugins/git/README.md"
alias gsur="git submodule update --remote --merge"
# bat
which bat > /dev/null
if [[ $? -eq 0 ]] then
alias cat="bat"
fi
# kubectl
alias k="kubectl"
alias kd="kubectl describe"
function kns() {
if [[ -z $1 ]]
then
kubectl get ns
else
kubectl config set-context \
$(kubectl config current-context) \
--namespace=$1
fi
}
# docker
alias d="docker"
alias de="docker exec"
alias dei="docker exec -it"
alias dl="docker logs"
alias dp="docker ps"
alias dc="docker-compose"
alias dcu="docker-compose up"
alias dcd="docker-compose down"
alias dcl="docker-compose logs"
# git worktree
alias gwa="git worktree add"
alias gwl="git worktree list"
alias gwr="git worktree remove"
alias grao="git remote add origin"
alias grro="git remote rm origin"
# tmux (warning: collisions with trunk)
alias t="tmux"
alias tl="tmux ls"
alias ta="tmux attach-session -t"
alias tn="tmux new-session -t"
# Make
alias m="make"
# cargo
alias c="cargo"
alias cr="cargo run"
alias cb="cargo build"
alias cf="cargo fmt"
alias ct="cargo test"
alias cl="cargo clippy"
# trunk (warning: collisions with tmux)
alias ts="trunk serve"
alias tso="trunk serve --open"
# npm
alias nr="npm run"
alias nrt="npm run test"
alias nrl="npm run lint"
alias nrd="npm run dev"
alias nrc="npm run check"
alias nrs="npm run start"
alias nrs="npm run build"
alias nrtc="npm run typecheck"
alias listen="lsof -i -P -n | grep LISTEN"
function nvims() {
if [ -f Session.vim ]; then
nvim -S Session.vim
else
echo "no session.vim file found"
fi
}
export MONGO_URI="mongodb://mongoadmin:supersecret@localhost:27017?authSource=admin"
function mongoup() {
docker run -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e MONGO_INITDB_ROOT_PASSWORD=supersecret -d mongo:latest
echo "connection string is $MONGO_URI"
echo 'available as $MONGO_URI'
}
#####################################################################
############################ macOS ##############################
############################ only ##############################
if [[ $OSTYPE == "darwin"* ]] ; then
#####################################################################
export XDG_CONFIG_HOME=$HOME/.config
# Disable DSUSP, which cause ^y to put process in background
# good for mutt because I can scroll up without exiting
stty dsusp undef
# -------------------------- HOMEBREW PACKAGES --------------------------------
# -------------------------- DJANGO ---------------------------------
export DJANGO_DEBUG=1
# -------------------------- MACOS STUPIDITY ------------------------
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY="YES"
#####################################################################
fi # macOS only ####################################################
#####################################################################
# -------------------------- OH-MY-ZSH ------------------------------
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
HYPHEN_INSENSITIVE="true"
DISABLE_UPDATE_PROMPT="true"
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git kubectl vi-mode)
source $ZSH/oh-my-zsh.sh
export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"
alias gbc="gb --sort=committerdate"
alias grbpr='git rebase -i $(git merge-base $(git_main_branch) HEAD)'
alias grrs='git reset --soft'
alias grl='git reflog'
alias grph='git rev-parse HEAD'
alias gpsup!='gpsup --force'
alias gfix="git add -A; git commit -m 'fixup'; grbpr"
# Git branch name; for when I need to manually do the above workflow, but still want
# a commit-stable branch name (maybe for later).
function gbrn() {
merge_base_message="$(git log $(git merge-base $(git_main_branch) HEAD)...HEAD --pretty='format:%s' | tail -n 1)"
sanitized_message=$(echo $merge_base_message \
| sed 's/ /-/g' \
| sed 's/(.*)//g' \
| sed 's/://g' \
| sed 's/\`//g' \
| sed 's/"//g' \
| sed 's/&//g' \
| sed "s/'//g" \
| sed "s/<//g" \
| sed "s/>//g" \
| sed 's/\///g' \
| sed 's/\$//g' \
| sed 's/\[//g' \
| sed 's/\]//g'
)
echo $sanitized_message
}
function goo() {
starting_branch=$(git_current_branch)
branch=$(date '+jack__%m/%d/%Y__%s')
if [[ ! -z "$1" ]]
then
branch=$1
fi
gco -b $branch || gco $branch
grhh $starting_branch
grbpr
# If the previous rebase had some merge conflicts, we're done; need to
# defer to the human.
if [[ "$?" != 0 ]]
then
return
fi
# If a branch was not provided, we are, at this point, sitting on a crappy
# generated branch. Instead, let's create a semantic branch name from the
# commit message, destroying the temporary branch that we're on, so that
# we are left with a nicely named one.
if [[ -z "$1" ]]
then
# rename the branch to match the commit message
semantic_branch_name=$(gbrn)
git branch -m $semantic_branch_name
if [[ $? != 0 ]]
then
git checkout $semantic_branch_name
git reset --hard $branch
git branch -D $branch
fi
fi
}
# Goo with a fixup before-hand
function goof() {
gfix
goo $@
}
# I use this with my one-branch workflow to create visual delimiters. See
# also https://jackdevries.com/post/oneBranch
alias gdelim='git commit --allow-empty -m "-------------------------------"'
alias gbt='gb -D temp; gco -b temp'
alias gp!='git push --force-with-lease'