Repository navigation
Expand file tree
/
Copy pathdot_utils.sh.tmpl
More file actions
262 lines (238 loc) · 5.95 KB
/
Copy pathdot_utils.sh.tmpl
File metadata and controls
262 lines (238 loc) · 5.95 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
alias ls='ls -FG'
alias ll='ls -lah'
alias mv='mv -nv'
alias rehash='hash -r'
alias p4="ping 4.2.2.2"
which prettyping >/dev/null && alias ping="prettyping"
alias ia="open -a 'IA Writer'"
alias marked="open -a 'Marked 2'"
alias cz=chezmoi
alias kcatss="kcat -X security.protocol=ssl -X enable.ssl.certificate.verification=false"
which bat >/dev/null && {
alias cat="bat"
export BAT_THEME='base16'
}
{{ if .mac }}
alias scan-ssh="dns-sd -B _ssh._tcp"
alias awake="pmset -g assertions | grep -i sleep"
{{ end }}
# update homebrew
function up() {
if ! [ -d "$(chezmoi source-path)/.jj" ]; then
chezmoi update --verbose
fi
brew update
brew upgrade --fetch-HEAD
# brew cu --cleanup --no-brew-update --yes
brew cleanup
if command -v gup >/dev/null; then
gup update
fi
gh extension upgrade --all
if command -v mise >/dev/null; then
mise up
fi
chezmoi status
}
# Run a command, copying the command line first and then capturing the output.
# This is in support of the alfred github details snippet
function details() {
if [ $# = 0 ]; then
echo -n "details <command> captures the command and its output "
echo "for the 'details' alfred snippet"
return
fi
echo "capturing output of ${*}..."
echo "\$ $*" | pbcopy
sleep 1 # let alfred pick it up
"$@" | pbcopy
echo "done."
}
function ss() {
local bundle="bundle"
if [ -x bin/bundle ]; then
bundle="bin/bundle"
fi
if [[ -e script/server ]]; then
if [[ -e Gemfile ]]; then
$bundle exec script/server "$@"
else
script/server "$@"
fi
elif [[ -e bin/rails ]]; then
$bundle exec rails server "$@"
else
echo "no server here"
return 1
fi
}
function sc() {
if [ -x bin/console ]; then
bin/console
return
fi
local bundle="bundle"
if [ -x bin/bundle ]; then
bundle="bin/bundle"
fi
if [[ -e script/console ]]; then
$bundle exec script/console "$@"
elif [[ -e bin/rails ]]; then
$bundle exec rails console "$@"
else
echo "no console here"
return 1
fi
}
alias sb='script/bootstrap'
alias st='script/test'
alias dc="docker compose"
function docker-cleanup() {
set -x
docker ps -aq --no-trunc -f status=exited | xargs docker rm
docker ps -aq --no-trunc -f status=created | xargs docker rm
docker images -q --filter dangling=true | xargs docker rmi
docker system prune --volumes -f
docker volume prune -f
set +x
}
# from https://github.com/junegunn/fzf/wiki/examples
fkill() {
local pid
if [ "$UID" != "0" ]; then
pid=$(ps -f -u $UID | sed 1d | fzf -m | awk '{print $2}')
else
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
fi
if [ "x$pid" != "x" ]; then
echo $pid | xargs kill -${1:-9}
fi
}
if [ -n "$(command -v zed)" ]; then
export EDITOR="zed"
export JJ_EDITOR="zed -w"
else
export EDITOR="code"
export JJ_EDITOR="code -w"
fi
function e() {
if [ -n "$1" ]; then
$EDITOR -n $1
else
$EDITOR -n . "$@"
fi
}
# mysql
export MYSQL_PS1="\u@\h \d> "
# format ag output for markdown
alias mdformat='ruby -lne '\''x, y = $_.split(/\s+/,2); puts "* #{x} `#{y}`"'\'''
function bo() {
local bundle="bundle" gems gem
if [ -x bin/bundle ]; then
bundle="bin/bundle"
fi
if ! gems=$($bundle list --paths); then
echo "$gems"
return 1
fi
if [ $# -gt 0 ]; then
gem=$(echo "$gems" | fzf -d/ --nth=-1 --with-nth=-1 -1 -q "$@")
else
gem=$(echo "$gems" | fzf -d/ --nth=-1 --with-nth=-1 -1)
fi
if [ -n "$gem" ]; then
e "$gem"
else
return 1
fi
}
function be() {
local bundle="bundle"
if [ -x bin/bundle ]; then
bundle="bin/bundle"
fi
$bundle exec "$@"
}
# git utils
function g() {
if [[ $# -gt 0 ]]; then
git "$@"
else
git status --short --branch -uall
fi
}
alias gam="git amend"
alias gap="git ap"
alias gbn="git branchname"
alias gc-="git co -"
alias gnb="git co -b"
alias gci="git ci"
alias gcm="git checkout \$(git main-branch)"
alias gd="git diff"
alias gi="git di"
alias gdi="git di"
alias js="jj status"
alias ju="jjui"
function gp() {
git pull --stat --all --prune --progress --autostash &&
git clean-merged-branches
}
function gpp() {
git pull --stat --all --prune --progress --autostash &&
git push
}
function main-branch() {
git fetch origin
git remote set-head origin -a
git branch -m master main
git branch -u origin/main main
}
# ref: https://github.com/anomalyco/opencode/issues/14561
ocs() {
local limit=${1:-50}
local db="$HOME/.local/share/opencode/opencode.db"
local selected
# Each line: "<sid>|<ts>|<shortdir>|<title>" — sid is field 1 (hidden)
selected=$(
sqlite3 "$db" \
"SELECT s.id,
strftime('%Y-%m-%d %H:%M', datetime(s.time_updated/1000, 'unixepoch', 'localtime')),
s.directory,
s.title
FROM session s
WHERE s.parent_id IS NULL
ORDER BY s.time_updated DESC
LIMIT $limit;" \
| while IFS='|' read -r sid ts dir title; do
printf '%s\t%s %-35s %s\n' "$sid" "$ts" "${dir/#$HOME/~}" "$title"
done \
| fzf \
--delimiter=$'\t' \
--with-nth=2 \
--ansi \
--no-sort \
--preview "
sid=\$(echo {} | cut -f1)
sqlite3 '$db' \"
SELECT
CASE json_extract(m.data, '$.role')
WHEN 'user' THEN '>> '
WHEN 'assistant' THEN ' '
ELSE ' '
END || json_extract(p.data, '$.text')
FROM part p
JOIN message m ON p.message_id = m.id
WHERE p.session_id = '\$sid'
AND json_extract(p.data, '$.type') = 'text'
ORDER BY p.time_created ASC;
\" | tail -20 | awk '/^>> /{print \"\"; print; next} {print}'
" \
--preview-window=bottom:60%:wrap:follow
)
[ -z "$selected" ] && return
local sid dir
sid=$(printf '%s' "$selected" | cut -f1)
dir=$(sqlite3 "$db" "SELECT directory FROM session WHERE id='$sid';")
cd "$dir" && opencode -s "$sid"
}
alias oc=opencode