-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.zprofile
More file actions
349 lines (288 loc) · 9.69 KB
/
.zprofile
File metadata and controls
349 lines (288 loc) · 9.69 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
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
#!/bin/zsh
# clone repo and cd into it. first arg is repo name, second is optional target
# dir. further args are passed through to jj git clone
oxclone() {
local repo_name="$1"
local target_dir="${2:-$1}" # accept a second arg but fall back to first
jj git clone "https://github.com/oxidecomputer/$repo_name.git" "$target_dir" "${@:3}"
cd "$target_dir"
}
ghclone() {
local org repo_name target_dir
if [[ "$1" == https://github.com/* ]]; then
local path="${1#https://github.com/}"
path="${path%.git}"
path="${path%/}"
org="${path%%/*}"
repo_name="${path#*/}"
elif [[ "$1" == */* ]]; then
org="${1%%/*}"
repo_name="${1#*/}"
fi
if [[ -z "$org" || -z "$repo_name" ]]; then
echo "usage: ghclone <org/repo | github-url> [target_dir]" >&2
return 1
fi
target_dir="${2:-$repo_name}"
jj git clone "https://github.com/$org/$repo_name.git" "$target_dir" "${@:3}"
cd "$target_dir"
}
alias jw="jj watch"
alias js="jj status"
alias jd="jj diff"
alias jdnl="jj diff '~package-lock.json & ~Cargo.lock'"
alias jdp="jj diff -r @-"
alias jdps="jj diff -r @- --stat"
alias jr="jj log -n 10"
alias jds="jj diff --stat"
alias jf="jj git fetch"
alias jp="jj git push"
alias jpm="jj git push --remote mine"
alias jpp="jj new && jj tug && jj git push"
# reset on top of main after being done with a PR
alias jrm="jj git fetch && jj new 'trunk()'"
alias jb="jj-jump" # see bin/jj-jump.ts
alias jsq="jj squash"
# alias sk="bun ~/oxide/skepsis/cli.ts"
alias sk="npx --prefix ~/oxide/skepsis tsx ~/oxide/skepsis/cli.ts"
alias cmux-desc='cmux workspace-action --action set-description --description'
function jjw() {
if [[ ("$1" == "create" || "$1" == "c") && "$#" -eq 1 ]]; then
local wspath
wspath="$(jjw-cmd create)" || return 1
cd "$wspath"
else
jjw-cmd "$@"
fi
}
# fzf jj bookmark picker
function zjb() {
jj b list -T 'separate("\t", name, normal_target.author().name(), normal_target.description())' |
column -t -s " " | # that's a tab lol
fzf --reverse --height '25%' --accept-nth=1
}
function curr_bookmark {
jj log --no-graph -r 'heads(::@ & bookmarks())' -T 'bookmarks.map(|b| b.name()).join("\n")' | head -1
}
# see bin/jpl.ts — jpl --help for usage
alias jdr='jj diff --from "$(curr_bookmark)@origin"'
alias jbs='jj tug'
# jj abandon branch
function jab() {
jj abandon -r "trunk()..$1" && jj bookmark forget "$1"
}
# choose a PR, returning the PR number only
function pick_pr() {
gh pr list --limit 100 --json headRefName,number,title,updatedAt,author --template \
'{{range .}}{{tablerow .number .title .author.name (timeago .updatedAt)}}{{end}}' |
fzf --height 25% --reverse --accept-nth=1
}
function jpr() {
local pr="$(pick_pr)"
[[ -z "$pr" ]] && return
local meta="$(gh pr view "$pr" --json headRefName,isCrossRepository)"
[[ -z "$meta" ]] && return
local branch="$(jq -r .headRefName <<<"$meta")"
local cross="$(jq -r .isCrossRepository <<<"$meta")"
echo "Checking out PR #$pr ($branch)"
if [[ "$cross" == "true" ]]; then
# Fork PR: branch isn't on origin, but GitHub exposes refs/pull/N/head.
# Fetch it into a local bookmark named pr-N.
git fetch origin "+refs/pull/$pr/head:refs/heads/pr-$pr" || return
jj new "pr-$pr"
else
jj git fetch
jj bookmark track "$branch@origin" 2>/dev/null
jj new "$branch"
fi
jj log -n 2
}
function nu-run {
nu -c "source ~/.config/nushell/zsh-functions.nu; $*"
}
function nu-alias {
alias "$1"="nu-run $1"
}
nu-alias jbt
nu-alias upgrade-ra
# prune branches, get list of delete remote references,
# attempt to delete local copies, ignoring errors
function gfp() {
git fetch --prune 2>&1 |
grep "\[deleted\]" |
sed -E "s/.+origin\///g" |
xargs git b -D 2>/dev/null
}
alias gr='git r'
alias gco='git co'
function grp() {
local ref="${1:-HEAD}"
git rev-parse "$ref" | ecopy
}
# Execute a command, echo output, and also copy it to the clipboard
function ecopy() {
local output
if [ $# -gt 0 ]; then
output="$*"
else
read -r output
fi
echo "$output (copied!)"
echo -n "$output" | pbcopy
}
alias server='python3 -m http.server 8000'
alias dev='npm run dev'
alias ts='if [ -x ./node_modules/.bin/tsgo ]; then ./node_modules/.bin/tsgo; else ./node_modules/.bin/tsc; fi'
alias e2e='npx playwright test'
alias e2ec='npx playwright test --project=chrome'
alias e2es='npx playwright test --project=safari'
alias e2ef='npx playwright test --project=firefox'
alias lint='npm run lint'
alias oxlint='./node_modules/.bin/oxlint'
# -v includes homepage, which is very wide
alias outdated='npm outdated --long --json | dq "R.pipe(data, R.entries, R.map(([k, v]) => [k, v.type.startsWith(\"dev\") ? \"dev\" : \"\", v.current, v.wanted, v.latest]), table)"'
alias outdated-v='npm outdated --long --json | dq "R.pipe(data, R.entries, R.map(([k, v]) => [k, v.type.startsWith(\"dev\") ? \"dev\" : \"\", v.current, v.wanted, v.latest, v.homepage]), table)"'
alias api-diff='~/oxide/console/tools/deno/api-diff.ts'
alias npm-clean='dust --no-percent-bars --depth 0 node_modules && echo "Deleting..." && rm -rf node_modules'
alias brew-outdated='brew outdated -v | grep -vf ~/.local/share/brew-outdated-exclude.txt'
function brew-why() {
for package in $(brew-outdated | awk '{ print $1 }'); do
echo "---------------"
echo "Package: $package"
brew uses --installed "$package"
done
}
alias nt='cargo t -p omicron-nexus --no-fail-fast --success-output immediate'
function ntpick() {
print -z -- "nt $(ntpicker)"
}
# list all nexus integration tests and run them through fzf to pick one
function ntpicker() {
rg -A1 "#\[nexus_test" --no-heading -N |
rg --replace '$module::$function' --no-filename \
--only-matching '/(?P<module>[^/]+).rs-[ ]*async fn (?P<function>test_[^(]+)' |
fzf --reverse
}
alias update-auth='EXPECTORATE=overwrite nt unauthorized'
alias clippy='cargo xtask clippy'
alias uuid='uuidgen | tr "[:upper:]" "[:lower:]" | ecopy'
alias cdk='cd ~/oxide/oxide-computer'
alias cdd='cd ~/oxide/docs'
alias cdo='cd ~/oxide/omicron'
alias cdc='cd ~/oxide/console'
alias ls='eza'
alias l='eza --all --long --group-directories-first --git'
alias lt='eza --all --tree --group-directories-first --git-ignore --level=2'
alias ltt='eza --all --tree --group-directories-first --git-ignore --level=3'
alias sgr='sg run -l rust --pattern'
alias sgt='sg run -l ts --pattern'
alias sgx='sg run -l tsx --pattern'
alias sga='sg run --pattern'
alias ais='ai --search -m gpt-5'
alias aisf='ai --search -m flash'
alias aif='ai -m flash'
alias cbd='cb -l diff'
# run the same prompt against several models (comma-separated after -m)
function aic() {
local models="" prompt=""
while [ $# -gt 0 ]; do
case $1 in
-m) models=$2; shift 2 ;;
*) prompt="$prompt${prompt:+ }$1"; shift ;;
esac
done
local stdin=""
[ ! -t 0 ] && stdin=$(cat)
local IFS=,
for m in $models; do
echo "=== $m ==="
if [ -n "$stdin" ]; then
printf '%s' "$stdin" | ai -e -m "$m" "$prompt"
else
ai -e -m "$m" "$prompt"
fi
echo
done
}
# default divisor is 4 and it seems pretty good, but you can pass a different one
function tok() {
local div=${1:-4}
wc -m | awk -v d="$div" '{printf("%.0f\n",$1/d)}'
}
# vipe: open $VISUAL/$EDITOR on a temp file, then emit contents to stdout
function vipe() {
local tmp
tmp="$(mktemp -t vipe)" || return
# prefill from stdin if present, else start empty
if [ -t 0 ]; then : >"$tmp"; else cat >"$tmp"; fi
# choose editor: VISUAL > EDITOR > vi (supports quoted args)
local -a cmd
if [[ -n $VISUAL ]]; then
cmd=("${(z)VISUAL}")
elif [[ -n $EDITOR ]]; then
cmd=("${(z)EDITOR}")
else
cmd=(vi)
fi
"${cmd[@]}" "$tmp" || { rm -f "$tmp"; return $?; }
cat "$tmp"
rm -f "$tmp"
}
function ghpr() {
gh pr list --limit 100 --json number,title,updatedAt,author --template \
'{{range .}}{{tablerow .number .title .author.name (timeago .updatedAt)}}{{end}}' |
fzf --height 25% --reverse --accept-nth=1 |
xargs gh pr checkout
}
alias prc='git push -u && gh pr create --web'
alias prv='gh pr view --web'
function oxdocs() {
(cd ~/oxide/docs/content && claude "/answer $*")
}
function jjdocs() {
(cd ~/repos/jj/docs && claude "/answer $*")
}
function hxdocs() {
(cd ~/repos/helix/book/src && claude "/answer $*")
}
# play happy sound on success and error sound on error
function bell() {
"$@"
(($?)) && SOUND="Sosumi" || SOUND="Funk"
(afplay "/System/Library/Sounds/$SOUND.aiff" &)
echo -e '\a' # terminal bell
}
function aijq() {
local input=$(cat)
local jq_str=$(ai --raw --ephemeral -m sonnet "write jq to $*. output the raw jq string only. no markdown, no codeblock, no backticks, no quotes")
echo "$input" | jq "$jq_str"
}
alias tviz='~/repos/things-viz/main.ts'
alias tsearch='~/repos/things-viz/search.ts'
function tts() {
if [ -p /dev/stdin ]; then
edge-playback --file -
else
edge-playback --text "$*"
fi
}
function upgrade-agents() {
parallel ::: \
'codex --version && npm install -g @openai/codex@latest && codex --version' \
'claude update' \
'opencode upgrade'
}
source "$HOME/.cargo/env"
export CLAUDE_CODE_NO_FLICKER=1
export PATH="$HOME/.local/bin:$PATH"
# omicron things obviously
export PATH="/Users/david/oxide/omicron/out/dendrite-stub/root/opt/oxide/dendrite/bin:$PATH"
export PATH="/Users/david/oxide/omicron/out/mgd/root/opt/oxide/mgd/bin:$PATH"
export PATH="/Users/david/oxide/omicron/out/clickhouse:$PATH"
export PATH="/Users/david/oxide/omicron/out/cockroachdb/bin:$PATH"
# gate these to suppress noisy warnings whenever codex runs things
[[ -o interactive ]] || return
eval "$(/opt/homebrew/bin/brew shellenv)"
eval "$(fnm env --use-on-cd --resolve-engines=false --shell zsh)"
# Added by Obsidian
export PATH="$PATH:/Applications/Obsidian.app/Contents/MacOS"