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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
|
set -o emacs
alias la='ls -a'
alias ll='ls -lh'
alias lt='ls -lth'
alias lla='ls -lha'
alias emacs='emacs -nw'
alias cap='ret=$?'
alias check='[ $ret == 0 ] && true || false'
lc() {
local target="${1:-.}"
find "$target" -type f \( \( -name '*.go' -a ! -name '*.sql.go' -a ! -name '*_templ.go' \) -o -name '*.templ' \) -print0 | xargs -0 wc -l
}
ls --color &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G'
Red="\033[0;31m"
Green='\033[0;32m'
Color_Off='\033[0m'
godir() {
cd $HOME/go/src/github.com/grindlemire/$@
}
export PATH=~/Apps/bin:~/dotfiles/scripts:$PATH
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
export PATH=/opt/homebrew/bin:$PATH
export PATH=~/Library/Python/3.9/bin:$PATH
export PATH=$HOME/.local/bin:$PATH
export EDITOR='vim'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$GOPATH/bin:/usr/local/bin:$PATH
git_sign_init() {
git config --global gpg.format ssh
git config --global user.signingKey "$(cat ~/.ssh/$1.pub)"
git config --global commit.gpgsign true
git config --global tag.gpgsign true
}
has_param() {
local term="$1"
shift
for arg; do
if [[ $arg == "$term" ]]; then
return 0
fi
done
return 1
}
gprune() {
CMD='git branch -D $branch'
if has_param '--dry' "$@"; then
CMD='echo "${Green}$branch ${Color_Off}is merged into main and can be deleted"'
else
git fetch --prune --all
fi
git checkout -q main && git for-each-ref refs/heads/ "--format=%(refname:short)" | \
while read branch;
do mergeBase=$(git merge-base main $branch) &&
[[ $(git cherry main $(git commit-tree $(git rev-parse "$branch^{tree}") -p $mergeBase -m _)) == "-"* ]] &&
eval "$CMD";
done
return 0
}
to_gif() {
FNAME="$(echo $1 | xargs -I file basename file .mov)"
cmd="ffmpeg -i $1 \
-vf \"fps=12,scale=1280:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse\" \
-loop 0 ${FNAME}.gif"
echo -e "${Green} Running Cmd:\n ${cmd}${Color_Off}\n"
eval "$cmd"
}
myip() {
ifconfig en0 | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'
}
update_terminal_cwd() {
local PWD_URL="file://$HOSTNAME${PWD// /%20}"
printf '\e]7;%s\a' "$PWD_URL"
}
clone() {
git clone [email protected]:$1
}
fixssh() {
. ensure-ssh-agent
}
gbranch() {
printf "%s" "$(git branch 2>/dev/null | grep \* | awk -F '\\* ' '{$0=$2}1')"
}
gpull() {
BRANCH=$(gbranch)
if [ -n "$1" ]; then
BRANCH=$1
fi
CMD="git pull origin ${BRANCH}"
echo -e "${Green} Running Cmd:\n ${CMD} ${Color_Off}\n"
eval "$CMD"
}
gpush() {
BRANCH=$(gbranch)
if [ -n "$1" ]; then
BRANCH=$1
fi
CMD="git push origin ${BRANCH}"
echo -e "${Green} Running Cmd:\n ${CMD} ${Color_Off}\n"
eval "$CMD"
}
gadd() {
CMD="git add ."
echo -e "${Green} Running Cmd:\n ${CMD} ${Color_Off}\n"
eval "$CMD"
}
gcommit() {
local NEED_GADD=true
if [ -n "$1" ] && [ "$1" = "-m" ]; then
shift
MSG="$@"
elif [ -n "$1" ]; then
MSG="$@"
else
gadd
NEED_GADD=false
echo -e "${Green}Generating commit message...${Color_Off}"
MSG=$(git diff --cached --diff-algorithm=minimal | claude -p "Generate a concise git commit message (subject line only, no body, max 72 chars) for these changes. Output ONLY the message, nothing else." 2>/dev/null)
CLAUDE_EXIT=$?
if [ -z "$MSG" ] || [ $CLAUDE_EXIT -ne 0 ]; then
MSG="snapshot $(date -u +'%Y-%m-%dT%H:%M:%SZ')"
echo -e "${Red}Claude generation failed, using timestamp${Color_Off}"
fi
fi
if [ "$NEED_GADD" = true ]; then
gadd
fi
CMD="git commit -m \"$MSG\""
echo -e "${Green} Running Cmd:\n ${CMD} ${Color_Off}\n"
fixssh > /dev/null 2>&1
eval "$CMD"
}
grevert() {
git reset --hard HEAD~1
}
grollback() {
git revert --no-edit HEAD
}
gpr() {
fixssh > /dev/null 2>&1
local current_branch=$(gbranch)
if [ -z "$current_branch" ]; then
echo -e "${Red}Error: Not in a git repository${Color_Off}"
return 1
fi
echo -e "${Green}Fetching latest main branch...${Color_Off}"
git fetch origin main --quiet 2>/dev/null || git fetch origin master --quiet 2>/dev/null
local main_branch="main"
if ! git rev-parse --verify origin/main >/dev/null 2>&1; then
if git rev-parse --verify origin/master >/dev/null 2>&1; then
main_branch="master"
else
echo -e "${Red}Error: Could not find main or master branch${Color_Off}"
return 1
fi
fi
echo -e "${Green}Generating PR title and description...${Color_Off}"
local diff_output
diff_output=$(git diff origin/${main_branch}..HEAD --diff-algorithm=minimal 2>/dev/null)
if [ -z "$diff_output" ]; then
echo -e "${Red}Error: No differences found between ${current_branch} and ${main_branch}${Color_Off}"
return 1
fi
local commit_log
commit_log=$(git log --oneline origin/${main_branch}..HEAD 2>/dev/null)
local pr_content
pr_content=$(echo -e "$commit_log\n\n---\n\n$diff_output" | claude -p "Generate a GitHub pull request title and description for these changes. The title should be concise (max 72 chars) and the description should include a brief summary and bullet points for notable changes. Format as:\n\nTITLE: <title>\n\nDESCRIPTION:\n<description>" 2>/dev/null)
local CLAUDE_EXIT=$?
if [ -z "$pr_content" ] || [ $CLAUDE_EXIT -ne 0 ]; then
echo -e "${Red}Claude generation failed, using commit log${Color_Off}"
local fallback_title=$(echo "$commit_log" | head -n 1 | sed 's/^[a-f0-9]* //' | awk '{print $1, $2}')
pr_content="TITLE: ${fallback_title}\n\nDESCRIPTION:\n## Changes\n$(echo "$commit_log" | head -n 10 | sed 's/^/- /')"
fi
local pr_title
local pr_description
pr_title=$(echo "$pr_content" | grep -A 1 "^TITLE:" | tail -n 1 | sed 's/^[[:space:]]*//')
pr_description=$(echo "$pr_content" | sed -n '/^DESCRIPTION:/,$p' | sed '1d' | sed 's/^[[:space:]]*//')
if [ -z "$pr_title" ]; then
pr_title=$(echo "$commit_log" | head -n 1 | sed 's/^[a-f0-9]* //' | awk '{print $1, $2}')
fi
if [ -z "$pr_description" ]; then
pr_description="## Changes\n$(echo "$commit_log" | sed 's/^/- /')"
fi
echo -e "\n${Green}=== PR Title ===${Color_Off}"
echo "$pr_title"
echo -e "\n${Green}=== PR Description ===${Color_Off}"
echo "$pr_description"
echo ""
}
grelease() {
fixssh > /dev/null 2>&1
local create_release=false
if [ "$1" = "-push" ]; then
create_release=true
shift
fi
local version_type="${1:-patch}"
if [[ ! "$version_type" =~ ^(patch|minor|major)$ ]]; then
echo -e "${Red}Error: Version type must be patch, minor, or major${Color_Off}"
return 1
fi
echo -e "${Green}Fetching latest tags...${Color_Off}"
git fetch --tags --quiet
local latest_tag=$(git tag -l 'v*' | sort -V | tail -n 1)
if [ -z "$latest_tag" ]; then
latest_tag="v0.0.0"
echo -e "${Green}No existing tags found, starting from v0.0.0${Color_Off}"
else
echo -e "${Green}Current latest tag: ${latest_tag}${Color_Off}"
fi
local version="${latest_tag#v}"
local major minor patch
IFS='.' read -r major minor patch <<< "$version"
major=${major:-0}
minor=${minor:-0}
patch=${patch:-0}
case "$version_type" in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
esac
local new_version="v${major}.${minor}.${patch}"
echo -e "${Green}New version: ${new_version}${Color_Off}"
if git rev-parse "$new_version" >/dev/null 2>&1; then
echo -e "${Red}Error: Tag ${new_version} already exists${Color_Off}"
return 1
fi
CMD="git tag -a ${new_version} -m \"Release ${new_version}\""
echo -e "${Green}Running Cmd:\n ${CMD}${Color_Off}\n"
eval "$CMD"
if [ $? -ne 0 ]; then
echo -e "${Red}Error: Failed to create tag${Color_Off}"
return 1
fi
CMD="git push origin ${new_version}"
echo -e "\n${Green}Running Cmd:\n ${CMD}${Color_Off}\n"
eval "$CMD"
if [ $? -ne 0 ]; then
echo -e "${Red}Error: Failed to push tag${Color_Off}"
return 1
fi
if [ "$create_release" = true ]; then
echo -e "${Green}Generating release notes...${Color_Off}"
local commit_log
if [ "$latest_tag" = "v0.0.0" ]; then
commit_log=$(git log --oneline HEAD)
else
commit_log=$(git log --oneline ${latest_tag}..${new_version})
fi
local release_title="$new_version"
local release_body
release_body=$(echo "$commit_log" | claude -p "Generate release notes in markdown for these commits. Include a brief summary and bullet points for notable changes. Output ONLY the markdown." 2>/dev/null)
local CLAUDE_BODY_EXIT=$?
if [ -z "$release_body" ] || [ $CLAUDE_BODY_EXIT -ne 0 ]; then
release_body="$commit_log"
echo -e "${Red}Claude body generation failed, using commit log${Color_Off}"
fi
local notes_file=$(mktemp)
echo "$release_body" > "$notes_file"
CMD="gh release create ${new_version} --title \"${release_title}\" --notes-file \"${notes_file}\""
echo -e "${Green}Running Cmd:\n ${CMD}${Color_Off}\n"
eval "$CMD"
local release_exit=$?
rm -f "$notes_file"
if [ $release_exit -ne 0 ]; then
echo -e "${Red}Error: Failed to create GitHub release${Color_Off}"
return 1
fi
fi
return 0
}
setopt PROMPT_SUBST
PROMPT='%(?^%F{green}[%n@%m] [%1~] [$(gbranch)]%f^%F{red}[%n@%m] [%1~] [$(gbranch)]%f)$ '
bindkey '^[[3~' delete-char
HISTFILE=$HOME/.zhistory
HISTSIZE=50000
SAVEHIST=50000
setopt SHARE_HISTORY
history() { builtin history 1 }
autoload -U up-line-or-beginning-search
autoload -U down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "^[[A" up-line-or-beginning-search
bindkey "^[[B" down-line-or-beginning-search
autoload -U compinit && compinit
zstyle ':completion:*' menu select
autoload -U zmv
setopt EXTENDED_GLOB
unsetopt NOMATCH
autoload -U add-zsh-hook
add-zsh-hook precmd update_terminal_cwd
add-zsh-hook preexec update_terminal_cwd
add-zsh-hook chpwd update_terminal_cwd
bindkey -v
bindkey "^R" history-incremental-search-backward
bindkey "^E" end-of-line
bindkey "^A" beginning-of-line
function zle-keymap-select zle-line-init zle-line-finish {
case $KEYMAP in
vicmd) echo -ne "\e[4 q";;
viins|main) echo -ne "\e[5 q";;
esac
zle reset-prompt
zle -R
}
zle -N zle-line-init
zle -N zle-line-finish
zle -N zle-keymap-select
HOMEBREW_AUTO_UPDATE_SECS=2629746
. ~/dotfiles/worktree.sh 2>/dev/null
. ~/dotfiles/macbook.sh &>/dev/null
. ~/dotfiles/virtualenv.sh 2>/dev/null
. ~/dotfiles/docker.sh 2>/dev/null
. ~/dotfiles/local-zshrc.sh 2>/dev/null
. "$HOME/.local/bin/env"
export PATH="/Users/joelholsteen/.antigravity/antigravity/bin:$PATH"
|