-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_aliases
284 lines (245 loc) · 9.51 KB
/
bash_aliases
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
ggm() {
local diff_output
local command_output
diff_output=$(git diff HEAD)
command_output=$(echo "$diff_output
For the above 'git diff HEAD' give me the command to commit these changes, describing what the changes are. Always use 'git commit -am' to add all the files. Conform to Conventional Commits specification." | llm -m claude-3-5-haiku-latest -s "Return only the command to be executed as a raw string, no string delimiters wrapping it, no yapping, no markdown, no fenced code blocks, what you return will be passed to subprocess.check_output() directly.
For example your output should look like this:
git commit -am \"feat: Add a new feature to the app\"
")
echo -e "\033[2mSuggested:\033[0m"
echo -e "\033[1;36m$command_output\033[0m"
echo -en "\033[1;33mPress [Enter] to execute, or 'n/N' to cancel: \033[0m"
read user_input
if [[ -z "$user_input" ]]; then
eval "$command_output"
echo -e "\033[1;32mCommand executed.\033[0m"
elif [[ "$user_input" =~ ^[nN]$ ]]; then
echo -e "\033[1;31mCommand cancelled.\033[0m"
else
echo -e "\033[1;31mInvalid input. Command cancelled.\033[0m"
fi
}
summarize() {
local text=""
local system_prompt=$(cat <<EOF
Summarize the following content.
Respond with just the text of the summary. Do not acknowledge my request or address me in any way. The output format is markdown. Begin always with a heading, e.g
## Summary
EOF
)
if [ ! -t 0 ]; then
text=$(cat)
else
# Otherwise use command line arguments
if [ $# -eq 0 ]; then
echo "Usage: summarize \"text to summarize\"" >&2
return 1
fi
text="$*"
fi
echo "<content>$text</content>
Summarize the above content. Your summary should be detailed and complete but written in a succinct form." | llm -m claude-3-5-haiku-latest --no-stream -s "$system_prompt"
}
parse_claims() {
local text=""
local system_prompt=$(cat <<EOF
Given the content, extract out a bullet list of main claims.
Respond with just the list. Do not acknowledge my request or address me in any way. The output format is markdown. Begin always with a heading, e.g
## Claims
- claim1
- claim2
EOF
)
if [ ! -t 0 ]; then
text=$(cat)
else
# Otherwise use command line arguments
if [ $# -eq 0 ]; then
echo "Usage: parse_claims \"text\"" >&2
return 1
fi
text="$*"
fi
echo "<content>$text</content>
Parse the above for distinct claims. Each one should be succinct, at most one sentence" | llm -m claude-3-5-haiku-latest --no-stream -s "$system_prompt"
}
transcribe() {
local url=""
local title=""
local temp_dir="/tmp/transcribe_$$"
local audio_file=""
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--title=*)
title="${1#*=}"
shift
;;
http*://*)
url="$1"
shift
;;
*)
echo "Usage: transcribe <url> [--title=<optional>]"
return 1
;;
esac
done
if [ -z "$url" ]; then
echo "Error: URL is required"
return 1
fi
# Extract video ID and use as default title if none provided
local video_id=$(echo "$url" | grep -o '[^/=]*$')
if [ -z "$title" ]; then
title="$video_id"
fi
# Create output directory structure
local output_dir="$HOME/Transcripts/$title"
mkdir -p "$output_dir"
# Check if all output files exist
if [ -f "$output_dir/transcript.json" ] && \
[ -f "$output_dir/summary.md" ] && \
[ -f "$output_dir/audio.m4a" ]; then
echo "All output files already exist in: $output_dir"
return 0
fi
# Construct R2 path
local r2_key="audio/$video_id.m4a"
local audio_url="https://media.substrate.run/$r2_key"
# First check for local audio
if [ -f "$output_dir/audio.m4a" ]; then
echo "Found local audio: $output_dir/audio.m4a"
audio_file="$output_dir/audio.m4a"
else
echo "Local audio not found, downloading from YouTube..."
mkdir -p "$temp_dir"
trap 'rm -rf "$temp_dir"' EXIT
if ! yt-dlp "$url" -f 140 -o "$temp_dir/%(id)s.%(ext)s" --quiet; then
echo "Error: Failed to download audio"
return 1
fi
audio_file=$(ls "$temp_dir"/*.m4a 2>/dev/null | head -n 1)
if [ -z "$audio_file" ]; then
echo "Error: No audio file found after download"
return 1
fi
cp "$audio_file" "$output_dir/audio.m4a"
audio_file="$output_dir/audio.m4a"
echo "Audio saved to: $output_dir/audio.m4a"
fi
# Check if we need to upload to R2
if aws s3api head-object --bucket substrate-public --key "$r2_key" --profile substrate_cf 2>/dev/null; then
echo "Audio already exists in R2: $audio_url"
else
echo "Uploading to Cloudflare R2..."
if ! aws s3 cp "$audio_file" "s3://substrate-public/$r2_key" --profile substrate_cf --quiet; then
echo "Error: Failed to upload to Cloudflare R2"
return 1
fi
echo "Audio uploaded to: $audio_url"
fi
# Check if transcript.json exists before proceeding with transcription
if [ ! -f "$output_dir/transcript.json" ]; then
# Submit transcription request
echo "Submitting transcription request..."
local response=$(curl --silent --request POST \
--url https://queue.fal.run/fal-ai/whisper \
--header "Authorization: Key $FAL_KEY" \
--header "Content-Type: application/json" \
--data "{
\"audio_url\": \"$audio_url\",
\"task\": \"transcribe\",
\"chunk_level\": \"segment\",
\"version\": \"3\",
\"batch_size\": 64,
\"language\": \"en\"
}")
local request_id=$(echo "$response" | grep -o '"request_id": *"[^"]*"' | sed 's/"request_id": *//; s/"//g')
if [ -z "$request_id" ]; then
echo "Error: Failed to get request ID from response"
return 1
fi
echo "Waiting for transcription to complete..."
local transcription_status=""
local max_attempts=60
local attempt=0
while [ $attempt -lt $max_attempts ]; do
transcription_status=$(curl --silent --request GET \
--url "https://queue.fal.run/fal-ai/whisper/requests/$request_id/status" \
--header "Authorization: Key $FAL_KEY" | grep -o '"status": *"[^"]*"' | sed 's/"status": *//; s/"//g')
if [ "$transcription_status" = "COMPLETED" ]; then
break
elif [ "$transcription_status" = "FAILED" ]; then
echo "Error: Transcription failed"
return 1
fi
echo -n "."
sleep 5
((attempt++))
done
echo
if [ $attempt -eq $max_attempts ]; then
echo "Error: Transcription timed out"
return 1
fi
# Get the transcription result
echo "Retrieving transcription..."
local result=$(curl --silent --request GET \
--url "https://queue.fal.run/fal-ai/whisper/requests/$request_id" \
--header "Authorization: Key $FAL_KEY")
echo "$result" > "$output_dir/transcript.json"
echo "Transcription saved to: $output_dir/transcript.json"
else
echo "Using existing transcript.json"
local result=$(cat "$output_dir/transcript.json")
fi
# Only run post-processing if summary.md doesn't exist
if [ ! -f "$output_dir/summary.md" ]; then
echo "Generating summary..."
# Run summarize and parse_claims in parallel and save to temporary files
{
echo "$result" | jq ".text" | summarize > "$output_dir/_summary.md" &
echo "$result" | jq ".text" | parse_claims > "$output_dir/_claims.md" &
wait
} 2>/dev/null
# Combine the results into a single markdown file with proper headers
{
echo "| Type | URL |"
echo "|------|-----|"
echo "| Video | $url |"
echo "| Audio | $audio_url |"
echo
cat "$output_dir/_summary.md"
echo
cat "$output_dir/_claims.md"
} > "$output_dir/summary.md"
echo "Summary saved to: $output_dir/summary.md"
else
echo "Post-processing already completed"
fi
return 0
}
alias glog='git log --oneline --pretty=format:"%C(green bold dim)%h%Creset %C(auto)%d %C(cyan bold)%an%Creset %s %C(blue bold)(%cr)%Creset" --decorate --abbrev-commit --date=relative'
alias grhh='git reset --hard @'
alias gg='git grep -i'
alias alog='adb logcat | grep -i'
alias devices='adb devices'
alias xcodeclean="rm -frd ~/Library/Developer/Xcode/DerivedData/* && rm -frd ~/Library/Caches/com.apple.dt.Xcode/*"
alias gdc='git diff --cached'
alias glast='git for-each-ref --count=40 --sort=-committerdate refs/heads/ --format="%(refname:short)" | fzf'
alias gcl='gco $(glast)'
alias up='git-up'
alias c='git commit -m'
alias ca='git commit -am'
alias dk="docker-compose"
alias cgrep="grep --color=always"
alias esr="~/code/substack/apps/substack/esr"
alias srs="/Users/robcheung/code/substack/packages/srs/srs"
alias watts="/usr/sbin/system_profiler SPPowerDataType | grep Wattage"
alias gcof="fzf-git-checkout"
alias cup="chiplet up"
alias cupr="chiplet up --overlay rob"
alias pc="pycharm"
alias rr="cargo run --"