Skip to content

Commit 03366f4

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/main'
2 parents 247dca6 + 60ea569 commit 03366f4

13 files changed

+133
-89
lines changed

.iterm2_shell_integration.fish

+44-37
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# along with this program; if not, write to the Free Software
1313
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1414

15-
if begin; status --is-interactive; and not functions -q -- iterm2_status; and [ "$ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX""$TERM" != screen ]; and [ "$TERM" != dumb ]; and [ "$TERM" != linux ]; end
15+
if begin; status --is-interactive; and not functions -q -- iterm2_status; and test "$ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX""$TERM" != screen; and test "$ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX""$TERM" != screen-256color; and test "$ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX""$TERM" != tmux-256color; and test "$TERM" != dumb; and test "$TERM" != linux; end
1616
function iterm2_status
1717
printf "\033]133;D;%s\007" $argv
1818
end
@@ -30,7 +30,11 @@ if begin; status --is-interactive; and not functions -q -- iterm2_status; and [
3030
# Tell terminal to create a mark at this location
3131
function iterm2_preexec --on-event fish_preexec
3232
# For other shells we would output status here but we can't do that in fish.
33-
printf "\033]133;C;\007"
33+
if test "$TERM_PROGRAM" = "iTerm.app"
34+
printf "\033]133;C;\r\007"
35+
else
36+
printf "\033]133;C;\007"
37+
end
3438
end
3539

3640
# Usage: iterm2_set_user_var key value
@@ -39,12 +43,12 @@ if begin; status --is-interactive; and not functions -q -- iterm2_status; and [
3943
# Gives a variable accessible in a badge by \(user.currentDirectory)
4044
# Calls to this go in iterm2_print_user_vars.
4145
function iterm2_set_user_var
42-
printf "\033]1337;SetUserVar=%s=%s\007" "$argv[1]" (printf "%s" "$argv[2]" | base64 | tr -d "\n")
46+
printf "\033]1337;SetUserVar=%s=%s\007" $argv[1] (printf "%s" $argv[2] | base64 | tr -d "\n")
4347
end
4448

4549
function iterm2_write_remotehost_currentdir_uservars
4650
if not set -q -g iterm2_hostname
47-
printf "\033]1337;RemoteHost=%s@%s\007\033]1337;CurrentDir=%s\007" $USER (hostname -f 2> /dev/null) $PWD
51+
printf "\033]1337;RemoteHost=%s@%s\007\033]1337;CurrentDir=%s\007" $USER (hostname -f 2>/dev/null) $PWD
4852
else
4953
printf "\033]1337;RemoteHost=%s@%s\007\033]1337;CurrentDir=%s\007" $USER $iterm2_hostname $PWD
5054
end
@@ -54,51 +58,52 @@ if begin; status --is-interactive; and not functions -q -- iterm2_status; and [
5458
if functions -q -- iterm2_print_user_vars
5559
iterm2_print_user_vars
5660
end
57-
5861
end
5962

6063
functions -c fish_prompt iterm2_fish_prompt
6164

62-
if functions -q -- fish_mode_prompt
63-
functions -c fish_mode_prompt iterm2_fish_mode_prompt
64-
function fish_mode_prompt --description 'Write out the mode prompt; do not replace this. Instead, change fish_mode_prompt before sourcing .iterm2_shell_integration.fish, or modify iterm2_fish_mode_prompt instead.'
65-
set -l last_status $status
65+
function iterm2_common_prompt
66+
set -l last_status $status
6667

67-
iterm2_status $last_status
68-
iterm2_write_remotehost_currentdir_uservars
69-
if not functions iterm2_fish_prompt | grep iterm2_prompt_mark > /dev/null
70-
iterm2_prompt_mark
71-
end
72-
sh -c "exit $last_status"
68+
iterm2_status $last_status
69+
iterm2_write_remotehost_currentdir_uservars
70+
if not functions iterm2_fish_prompt | string match -q "*iterm2_prompt_mark*"
71+
iterm2_prompt_mark
72+
end
73+
return $last_status
74+
end
7375

74-
iterm2_fish_mode_prompt
76+
function iterm2_check_function -d "Check if function is defined and non-empty"
77+
test (functions $argv[1] | grep -cvE '^ *(#|function |end$|$)') != 0
78+
end
79+
80+
if iterm2_check_function fish_mode_prompt
81+
# Only override fish_mode_prompt if it is non-empty. This works around a problem created by a
82+
# workaround in starship: https://github.com/starship/starship/issues/1283
83+
functions -c fish_mode_prompt iterm2_fish_mode_prompt
84+
function fish_mode_prompt --description 'Write out the mode prompt; do not replace this. Instead, change fish_mode_prompt before sourcing .iterm2_shell_integration.fish, or modify iterm2_fish_mode_prompt instead.'
85+
iterm2_common_prompt
86+
iterm2_fish_mode_prompt
7587
end
7688

7789
function fish_prompt --description 'Write out the prompt; do not replace this. Instead, change fish_prompt before sourcing .iterm2_shell_integration.fish, or modify iterm2_fish_prompt instead.'
78-
# Remove the trailing newline from the original prompt. This is done
79-
# using the string builtin from fish, but to make sure any escape codes
80-
# are correctly interpreted, use %b for printf.
81-
printf "%b" (string join "\n" (iterm2_fish_prompt))
90+
# Remove the trailing newline from the original prompt. This is done
91+
# using the string builtin from fish, but to make sure any escape codes
92+
# are correctly interpreted, use %b for printf.
93+
printf "%b" (string join "\n" (iterm2_fish_prompt))
8294

83-
iterm2_prompt_end
95+
iterm2_prompt_end
8496
end
8597
else
86-
# Pre-2.2 path
87-
function fish_prompt --description 'Write out the prompt; do not replace this. Instead, change fish_prompt before sourcing .iterm2_shell_integration.fish, or modify iterm2_fish_prompt instead.'
88-
# Save our status
89-
set -l last_status $status
98+
# fish_mode_prompt is empty or unset.
99+
function fish_prompt --description 'Write out the mode prompt; do not replace this. Instead, change fish_mode_prompt before sourcing .iterm2_shell_integration.fish, or modify iterm2_fish_mode_prompt instead.'
100+
iterm2_common_prompt
90101

91-
iterm2_status $last_status
92-
if not functions iterm2_fish_prompt | grep iterm2_prompt_mark > /dev/null
93-
iterm2_prompt_mark
94-
end
102+
# Remove the trailing newline from the original prompt. This is done
103+
# using the string builtin from fish, but to make sure any escape codes
104+
# are correctly interpreted, use %b for printf.
105+
printf "%b" (string join "\n" (iterm2_fish_prompt))
95106

96-
# Restore the status
97-
sh -c "exit $last_status"
98-
# Remove the trailing newline from the original prompt. This is done
99-
# using the string builtin from fish, but to make sure any escape codes
100-
# are correctly interpreted, use %b for printf.
101-
printf "%b" (string join "\n" (iterm2_fish_prompt))
102107
iterm2_prompt_end
103108
end
104109
end
@@ -107,7 +112,7 @@ if begin; status --is-interactive; and not functions -q -- iterm2_status; and [
107112
if not set -q -g iterm2_hostname
108113
# hostname -f is fast on macOS so don't cache it. This lets us get an updated version when
109114
# it changes, such as if you attach to a VPN.
110-
if [ (uname) != Darwin ]
115+
if test (uname) != Darwin
111116
set -g iterm2_hostname (hostname -f 2>/dev/null)
112117
# some flavors of BSD (i.e. NetBSD and OpenBSD) don't have the -f option
113118
if test $status -ne 0
@@ -117,5 +122,7 @@ if begin; status --is-interactive; and not functions -q -- iterm2_status; and [
117122
end
118123

119124
iterm2_write_remotehost_currentdir_uservars
120-
printf "\033]1337;ShellIntegrationVersion=11;shell=fish\007"
125+
printf "\033]1337;ShellIntegrationVersion=19;shell=fish\007"
121126
end
127+
128+
alias imgcat=$HOME/.iterm2/imgcat;alias imgls=$HOME/.iterm2/imgls;alias it2api=$HOME/.iterm2/it2api;alias it2attention=$HOME/.iterm2/it2attention;alias it2cat=$HOME/.iterm2/it2cat;alias it2check=$HOME/.iterm2/it2check;alias it2copy=$HOME/.iterm2/it2copy;alias it2dl=$HOME/.iterm2/it2dl;alias it2getvar=$HOME/.iterm2/it2getvar;alias it2git=$HOME/.iterm2/it2git;alias it2profile=$HOME/.iterm2/it2profile;alias it2setcolor=$HOME/.iterm2/it2setcolor;alias it2setkeylabel=$HOME/.iterm2/it2setkeylabel;alias it2ssh=$HOME/.iterm2/it2ssh;alias it2tip=$HOME/.iterm2/it2tip;alias it2ul=$HOME/.iterm2/it2ul;alias it2universion=$HOME/.iterm2/it2universion

.prettierrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// If you change anything here, you probably have to reload vscode windows to pick it up.
44
module.exports = {
5-
printWidth: 110,
5+
printWidth: 160,
66
tabWidth: 2,
77
singleQuote: true,
88
trailingComma: 'es5',

bin/render-streaming-markdown.ts

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// usage:
2+
// cat README.md | deno run --allow-env --allow-read --allow-run bin/render-streaming-markdown.ts
3+
//
4+
5+
import $ from 'jsr:@david/[email protected]'
6+
// todo: replace dax with this:
7+
// import { exec } from 'https://deno.land/std/process.mod.ts';
8+
import { writeAllSync } from 'https://deno.land/[email protected]/streams/mod.ts';
9+
10+
let inputBuffer = ""
11+
12+
const decoder = new TextDecoder()
13+
const encoder = new TextEncoder()
14+
15+
// This style works well for prompt.. but not chat
16+
for await (const chunk of Deno.stdin.readable) {
17+
// show immediately, but meanwhile…
18+
writeAllSync(Deno.stdout, chunk);
19+
// Collect it.
20+
inputBuffer += decoder.decode(chunk);
21+
}
22+
23+
// and now re-render it.
24+
if (inputBuffer) {
25+
console.log('⬇️… and now rendered…⬇️');
26+
const output = await $`glow --style auto`.stdinText(inputBuffer).text()
27+
writeAllSync(Deno.stdout, encoder.encode(output));
28+
}
29+
30+
31+
// This is a newline-buffered variant to avoid getting extra newlines in the output because we send it to glow too eagerly
32+
// it works but... the next problem is backtick codeblocks are broken up and... i'm sure there's more.
33+
// definitely need a better solution
34+
35+
// let remainingContent = '';
36+
// for await (const chunk of Deno.stdin.readable) {
37+
// const decoded = remainingContent + decoder.decode(chunk);
38+
39+
// const lastNewline = decoded.lastIndexOf("\n");
40+
// if (lastNewline !== -1) {
41+
// // Flush everything up to it
42+
// const output = await $`glow --style auto`.stdinText(decoded.substring(0, lastNewline + 1)).text()
43+
// writeAllSync(Deno.stdout, encoder.encode(output));
44+
45+
// // Hold onto the remaining content to flush with the next chunk
46+
// remainingContent = decoded.substring(lastNewline + 1);
47+
// }
48+
// }
49+
50+
// // Flush any remaining content
51+
// if (remainingContent) {
52+
// const output = await $`glow --style auto`.stdinText(remainingContent).text()
53+
// writeAllSync(Deno.stdout, encoder.encode(output));
54+
// }

brew.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/bash
22

33
# Install command-line tools using Homebrew
44

docs/clearing-disk-space.sh

-41
This file was deleted.

docs/common-things.sh

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#!/bin/bash
2-
3-
4-
1+
# shellcheck disable=2148
52

63

74
# listing all useragent from your logs
@@ -56,9 +53,9 @@ rm $chromefilename
5653

5754
# measuring time in fish shell:
5855

59-
set -l then (gdate +%s%N);
60-
sleep 0.5;
61-
set -l andnow (gdate +%s%N); echo cool (math ( math $andnow - $then) / 1000 / 1000 )
56+
# set -l earlier (gdate +%s%N);
57+
# sleep 0.5;
58+
# set -l andnow (gdate +%s%N); echo cool (math ( math $andnow - $earlier) / 1000 / 1000 )
6259

6360

6461

docs/upsampling images.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# shellcheck disable=2148
2+
13
# basic
24
convert image-filename.png -resize 300% image-filename.3x-basic.png
35

fish/aliases.fish

+21
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,28 @@ alias brew_update="brew -v update; brew upgrade --force-bottle --cleanup; brew c
139139
alias update_brew_npm_gem='brew_update; npm install npm -g; npm update -g; sudo gem update --system; sudo gem update --no-document'
140140

141141

142+
function gemi
143+
# using https://github.com/simonw/llm-gemini and llm
144+
# no args? chat. otherwise use prompt, and allow unquoted stuff to work too
145+
# gemi
146+
# gemi tell me a joke
147+
# gemi "tell me a joke"
148+
if test -z "$argv[1]"
149+
# no markdown parsing here without some real fancy stuff. because you dont want to send to markdown renderer (glow) inbetween backticks, etc.
150+
llm chat --continue -m gemini-1.5-pro-latest
151+
else
152+
llm prompt -m gemini-1.5-pro-latest "$argv" && echo "⬇️… and now rendered…⬇️" && llm logs -r | glow
153+
end
154+
end
142155

156+
function openai
157+
# using llm. same dealio as above
158+
if test -z "$argv[1]"
159+
llm chat --continue -m gpt-4o
160+
else
161+
llm prompt -m gpt-4o "$argv" && echo "⬇️… and now rendered…⬇️" && llm logs -r | glow
162+
end
163+
end
143164

144165
# project-specific shorthands
145166

fish/config.fish

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ end
9898

9999
# TODO debug this
100100
# this currently messes with newlines in my prompt. lets debug it later.
101-
# test -e {$HOME}/.iterm2_shell_integration.fish ; and source {$HOME}/.iterm2_shell_integration.fish
101+
test -e {$HOME}/.iterm2_shell_integration.fish ; and source {$HOME}/.iterm2_shell_integration.fish

fish/functions/fish_prompt.fish

+2
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ function fish_prompt
408408
echo ''
409409
end
410410

411+
iterm2_prompt_mark # manually place it
412+
411413
# echo -sn $user "@" $hostname
412414
set_color $lucid_cwd_color
413415
echo -sn $cwd

setup-a-new-machine.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# copy paste this file in bit by bit.
22
# don't run it.
3+
# shellcheck disable=2148
34
echo "do not run this script in one go. hit ctrl-c NOW"
45
read -n 1
56

setup-chromium.sh

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## Chromium hacking
33

44
# improve perf of git inside of chromium checkout
5+
# shellcheck disable=2148
56

67
# Read https://chromium.googlesource.com/chromium/src/+/HEAD/docs/mac_build_instructions.md#improving-performance-of-git-commands
78
# ... and do it all.

symlink-setup.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ main() {
159159
local sourceFile=""
160160
local targetFile=""
161161

162-
for i in ${FILES_TO_SYMLINK[@]}; do
162+
for i in "${FILES_TO_SYMLINK[@]}"; do
163163

164164
sourceFile="$(pwd)/$i"
165165
targetFile="$HOME/$(printf "%s" "$i" | sed "s/.*\/\(.*\)/\1/g")"

0 commit comments

Comments
 (0)