From b1c748d66b53fc0d41810089d714dd32836ac26b Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Thu, 16 May 2024 09:38:53 -0700 Subject: [PATCH 1/7] prettier: printWidth 160 default . can always lower it at project level --- .prettierrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.prettierrc.js b/.prettierrc.js index 1c352bd9c..36457433b 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -2,7 +2,7 @@ // If you change anything here, you probably have to reload vscode windows to pick it up. module.exports = { - printWidth: 110, + printWidth: 160, tabWidth: 2, singleQuote: true, trailingComma: 'es5', From ef553e9557f6ac68fb5fc60fe651b69b16ddc6d2 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Sat, 1 Jun 2024 10:02:04 -0700 Subject: [PATCH 2/7] bump iterm shell integration to latest --- .iterm2_shell_integration.fish | 81 ++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/.iterm2_shell_integration.fish b/.iterm2_shell_integration.fish index 6d2eada5b..90eddf64b 100755 --- a/.iterm2_shell_integration.fish +++ b/.iterm2_shell_integration.fish @@ -12,7 +12,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -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 +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 function iterm2_status printf "\033]133;D;%s\007" $argv end @@ -30,7 +30,11 @@ if begin; status --is-interactive; and not functions -q -- iterm2_status; and [ # Tell terminal to create a mark at this location function iterm2_preexec --on-event fish_preexec # For other shells we would output status here but we can't do that in fish. - printf "\033]133;C;\007" + if test "$TERM_PROGRAM" = "iTerm.app" + printf "\033]133;C;\r\007" + else + printf "\033]133;C;\007" + end end # Usage: iterm2_set_user_var key value @@ -39,12 +43,12 @@ if begin; status --is-interactive; and not functions -q -- iterm2_status; and [ # Gives a variable accessible in a badge by \(user.currentDirectory) # Calls to this go in iterm2_print_user_vars. function iterm2_set_user_var - printf "\033]1337;SetUserVar=%s=%s\007" "$argv[1]" (printf "%s" "$argv[2]" | base64 | tr -d "\n") + printf "\033]1337;SetUserVar=%s=%s\007" $argv[1] (printf "%s" $argv[2] | base64 | tr -d "\n") end function iterm2_write_remotehost_currentdir_uservars if not set -q -g iterm2_hostname - printf "\033]1337;RemoteHost=%s@%s\007\033]1337;CurrentDir=%s\007" $USER (hostname -f 2> /dev/null) $PWD + printf "\033]1337;RemoteHost=%s@%s\007\033]1337;CurrentDir=%s\007" $USER (hostname -f 2>/dev/null) $PWD else printf "\033]1337;RemoteHost=%s@%s\007\033]1337;CurrentDir=%s\007" $USER $iterm2_hostname $PWD end @@ -54,51 +58,52 @@ if begin; status --is-interactive; and not functions -q -- iterm2_status; and [ if functions -q -- iterm2_print_user_vars iterm2_print_user_vars end - end functions -c fish_prompt iterm2_fish_prompt - if functions -q -- fish_mode_prompt - functions -c fish_mode_prompt iterm2_fish_mode_prompt - 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.' - set -l last_status $status + function iterm2_common_prompt + set -l last_status $status - iterm2_status $last_status - iterm2_write_remotehost_currentdir_uservars - if not functions iterm2_fish_prompt | grep iterm2_prompt_mark > /dev/null - iterm2_prompt_mark - end - sh -c "exit $last_status" + iterm2_status $last_status + iterm2_write_remotehost_currentdir_uservars + if not functions iterm2_fish_prompt | string match -q "*iterm2_prompt_mark*" + iterm2_prompt_mark + end + return $last_status + end - iterm2_fish_mode_prompt + function iterm2_check_function -d "Check if function is defined and non-empty" + test (functions $argv[1] | grep -cvE '^ *(#|function |end$|$)') != 0 + end + + if iterm2_check_function fish_mode_prompt + # Only override fish_mode_prompt if it is non-empty. This works around a problem created by a + # workaround in starship: https://github.com/starship/starship/issues/1283 + functions -c fish_mode_prompt iterm2_fish_mode_prompt + 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.' + iterm2_common_prompt + iterm2_fish_mode_prompt end 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.' - # Remove the trailing newline from the original prompt. This is done - # using the string builtin from fish, but to make sure any escape codes - # are correctly interpreted, use %b for printf. - printf "%b" (string join "\n" (iterm2_fish_prompt)) + # Remove the trailing newline from the original prompt. This is done + # using the string builtin from fish, but to make sure any escape codes + # are correctly interpreted, use %b for printf. + printf "%b" (string join "\n" (iterm2_fish_prompt)) - iterm2_prompt_end + iterm2_prompt_end end else - # Pre-2.2 path - 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.' - # Save our status - set -l last_status $status + # fish_mode_prompt is empty or unset. + 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.' + iterm2_common_prompt - iterm2_status $last_status - if not functions iterm2_fish_prompt | grep iterm2_prompt_mark > /dev/null - iterm2_prompt_mark - end + # Remove the trailing newline from the original prompt. This is done + # using the string builtin from fish, but to make sure any escape codes + # are correctly interpreted, use %b for printf. + printf "%b" (string join "\n" (iterm2_fish_prompt)) - # Restore the status - sh -c "exit $last_status" - # Remove the trailing newline from the original prompt. This is done - # using the string builtin from fish, but to make sure any escape codes - # are correctly interpreted, use %b for printf. - printf "%b" (string join "\n" (iterm2_fish_prompt)) iterm2_prompt_end end end @@ -107,7 +112,7 @@ if begin; status --is-interactive; and not functions -q -- iterm2_status; and [ if not set -q -g iterm2_hostname # hostname -f is fast on macOS so don't cache it. This lets us get an updated version when # it changes, such as if you attach to a VPN. - if [ (uname) != Darwin ] + if test (uname) != Darwin set -g iterm2_hostname (hostname -f 2>/dev/null) # some flavors of BSD (i.e. NetBSD and OpenBSD) don't have the -f option if test $status -ne 0 @@ -117,5 +122,7 @@ if begin; status --is-interactive; and not functions -q -- iterm2_status; and [ end iterm2_write_remotehost_currentdir_uservars - printf "\033]1337;ShellIntegrationVersion=11;shell=fish\007" + printf "\033]1337;ShellIntegrationVersion=19;shell=fish\007" end + +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 From d8cb34d1791a3acc3ba635eabbad43cba911a32d Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Sat, 1 Jun 2024 11:30:18 -0700 Subject: [PATCH 3/7] iterm shell integration looking okay finally. --- fish/config.fish | 2 +- fish/functions/fish_prompt.fish | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/fish/config.fish b/fish/config.fish index 3a71dd3b4..40ce102f5 100644 --- a/fish/config.fish +++ b/fish/config.fish @@ -98,4 +98,4 @@ end # TODO debug this # this currently messes with newlines in my prompt. lets debug it later. -# test -e {$HOME}/.iterm2_shell_integration.fish ; and source {$HOME}/.iterm2_shell_integration.fish +test -e {$HOME}/.iterm2_shell_integration.fish ; and source {$HOME}/.iterm2_shell_integration.fish diff --git a/fish/functions/fish_prompt.fish b/fish/functions/fish_prompt.fish index c06dee161..5a4c25e11 100644 --- a/fish/functions/fish_prompt.fish +++ b/fish/functions/fish_prompt.fish @@ -408,6 +408,8 @@ function fish_prompt echo '' end + iterm2_prompt_mark # manually place it + # echo -sn $user "@" $hostname set_color $lucid_cwd_color echo -sn $cwd From 33229224cbac06f7907df522cf6af909b8694368 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Sat, 1 Jun 2024 11:30:40 -0700 Subject: [PATCH 4/7] gemini command and markdown formatting --- bin/render-streaming-markdown.ts | 21 +++++++++++++++++++++ fish/aliases.fish | 8 ++++++++ 2 files changed, 29 insertions(+) create mode 100644 bin/render-streaming-markdown.ts diff --git a/bin/render-streaming-markdown.ts b/bin/render-streaming-markdown.ts new file mode 100644 index 000000000..2a25a0eb7 --- /dev/null +++ b/bin/render-streaming-markdown.ts @@ -0,0 +1,21 @@ +// usage: +// cat README.md | deno run --allow-env --allow-read --allow-run bin/render-streaming-markdown.ts +// + +import $ from "jsr:@david/dax@0.41.0" +import { writeAllSync } from 'https://deno.land/std@v0.190.0/streams/mod.ts'; + +let inputBuffer = "" + +const decoder = new TextDecoder() +const encoder = new TextEncoder() + +for await (const chunk of Deno.stdin.readable) { + const decoded = decoder.decode(chunk); + inputBuffer += decoded + // console.log("$$$$$$$$$$", decoder.decode(chunk), "$$$zzz$$$") + + // --style auto is there to force it to output styled https://github.com/charmbracelet/glow/blob/2430b0a/main.go#L158 + const output = await $`glow --style auto`.stdinText(decoded).text() + writeAllSync(Deno.stdout, encoder.encode(output)); +} diff --git a/fish/aliases.fish b/fish/aliases.fish index 0f8e45d94..1646552d4 100644 --- a/fish/aliases.fish +++ b/fish/aliases.fish @@ -139,7 +139,15 @@ alias brew_update="brew -v update; brew upgrade --force-bottle --cleanup; brew c alias update_brew_npm_gem='brew_update; npm install npm -g; npm update -g; sudo gem update --system; sudo gem update --no-document' +abbr gemini "llm -m gemini-1.5-pro-latest" +function gemi + if test -n "$argv[1]" + llm prompt -m gemini-1.5-pro-latest $argv[1] | deno run --allow-env --allow-read --allow-run bin/render-streaming-markdown.ts + else + llm chat --continue -m gemini-1.5-pro-latest | deno run --allow-env --allow-read --allow-run bin/render-streaming-markdown.ts + end +end # project-specific shorthands From 3f598043d2d55a95085d568ec7ced1388ee08634 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Sat, 1 Jun 2024 11:58:24 -0700 Subject: [PATCH 5/7] gemi command to run gemini prompt/chat from cmd line --- bin/render-streaming-markdown.ts | 45 +++++++++++++++++++++++++++----- fish/aliases.fish | 5 ++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/bin/render-streaming-markdown.ts b/bin/render-streaming-markdown.ts index 2a25a0eb7..6649310f8 100644 --- a/bin/render-streaming-markdown.ts +++ b/bin/render-streaming-markdown.ts @@ -2,7 +2,9 @@ // cat README.md | deno run --allow-env --allow-read --allow-run bin/render-streaming-markdown.ts // -import $ from "jsr:@david/dax@0.41.0" +import $ from 'jsr:@david/dax@0.41.0' +// todo: replace dax with this: +// import { exec } from 'https://deno.land/std/process.mod.ts'; import { writeAllSync } from 'https://deno.land/std@v0.190.0/streams/mod.ts'; let inputBuffer = "" @@ -10,12 +12,43 @@ let inputBuffer = "" const decoder = new TextDecoder() const encoder = new TextEncoder() +// This style works well for prompt.. but not chat for await (const chunk of Deno.stdin.readable) { - const decoded = decoder.decode(chunk); - inputBuffer += decoded - // console.log("$$$$$$$$$$", decoder.decode(chunk), "$$$zzz$$$") + // show immediately, but meanwhile… + writeAllSync(Deno.stdout, chunk); + // Collect it. + inputBuffer += decoder.decode(chunk); +} - // --style auto is there to force it to output styled https://github.com/charmbracelet/glow/blob/2430b0a/main.go#L158 - const output = await $`glow --style auto`.stdinText(decoded).text() +// and now re-render it. +if (inputBuffer) { + console.log('⬇️… and now rendered…⬇️'); + const output = await $`glow --style auto`.stdinText(inputBuffer).text() writeAllSync(Deno.stdout, encoder.encode(output)); } + + +// This is a newline-buffered variant to avoid getting extra newlines in the output because we send it to glow too eagerly +// it works but... the next problem is backtick codeblocks are broken up and... i'm sure there's more. +// definitely need a better solution + +// let remainingContent = ''; +// for await (const chunk of Deno.stdin.readable) { +// const decoded = remainingContent + decoder.decode(chunk); + +// const lastNewline = decoded.lastIndexOf("\n"); +// if (lastNewline !== -1) { +// // Flush everything up to it +// const output = await $`glow --style auto`.stdinText(decoded.substring(0, lastNewline + 1)).text() +// writeAllSync(Deno.stdout, encoder.encode(output)); + +// // Hold onto the remaining content to flush with the next chunk +// remainingContent = decoded.substring(lastNewline + 1); +// } +// } + +// // Flush any remaining content +// if (remainingContent) { +// const output = await $`glow --style auto`.stdinText(remainingContent).text() +// writeAllSync(Deno.stdout, encoder.encode(output)); +// } diff --git a/fish/aliases.fish b/fish/aliases.fish index 1646552d4..d56e09c3a 100644 --- a/fish/aliases.fish +++ b/fish/aliases.fish @@ -142,10 +142,11 @@ alias update_brew_npm_gem='brew_update; npm install npm -g; npm update -g; sudo abbr gemini "llm -m gemini-1.5-pro-latest" function gemi + # using https://github.com/simonw/llm-gemini and llm if test -n "$argv[1]" - llm prompt -m gemini-1.5-pro-latest $argv[1] | deno run --allow-env --allow-read --allow-run bin/render-streaming-markdown.ts + llm prompt -m gemini-1.5-pro-latest $argv[1] | deno run --allow-env --allow-read --allow-run bin/render-streaming-markdown.ts else - llm chat --continue -m gemini-1.5-pro-latest | deno run --allow-env --allow-read --allow-run bin/render-streaming-markdown.ts + llm chat --continue -m gemini-1.5-pro-latest end end From f37cdbfd8bc35096e846bceaa1250b57535042e2 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Sat, 1 Jun 2024 12:25:54 -0700 Subject: [PATCH 6/7] pacify shellcheck --- brew.sh | 2 +- docs/clearing-disk-space.sh | 41 ------------------------------------- docs/common-things.sh | 11 ++++------ docs/upsampling images.sh | 2 ++ setup-a-new-machine.sh | 1 + setup-chromium.sh | 1 + symlink-setup.sh | 2 +- 7 files changed, 10 insertions(+), 50 deletions(-) delete mode 100644 docs/clearing-disk-space.sh diff --git a/brew.sh b/brew.sh index a66bca84b..7fa331563 100755 --- a/brew.sh +++ b/brew.sh @@ -1,4 +1,4 @@ - #!/bin/bash +#!/bin/bash # Install command-line tools using Homebrew diff --git a/docs/clearing-disk-space.sh b/docs/clearing-disk-space.sh deleted file mode 100644 index 549fd87f7..000000000 --- a/docs/clearing-disk-space.sh +++ /dev/null @@ -1,41 +0,0 @@ -# won't last long but will give you 1G. -sudo rm /private/var/vm/sleepimage - -# Clean up system logs and temporary files -# http://www.thexlab.com/faqs/maintscripts.html -sudo periodic daily weekly monthly - - -# remove old homebrew versions -# https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/FAQ.md#how-do-i-uninstall-old-versions-of-a-formula -brew cleanup -n # to see what would get cleaned up -brew cleanup # to do it. - -cask cleanup - - -~/Library/Caches/Google/Chrome Canary/Default -~/Library/Caches/Google/Chrome/Default - - -# diskexplorer X is good for big files -# daisy disk is good for big folders - -# XCODE is enormous -# kill cache -rm -rf ~/Library/Caches/com.apple.dt.Xcode -# appears that XCode can survive deleting ALL documentation sets! -~/Library/Developer/Shared/Documentation/DocSets -/Applications/Xcode.app/Contents/Developer/Documentation/DocSets -# other simulators can be here. -/Library/Developer/CoreSimulator/Profiles/Runtimes - -# use appcleaner to remove weird shit - -emptytrash - -# investigate manually - https://dev.yorhel.nl/ncdu -ncdu ~ - -# really roll up those sleeves and get dirty -ncdu / diff --git a/docs/common-things.sh b/docs/common-things.sh index 43e9e42d7..e87baa701 100644 --- a/docs/common-things.sh +++ b/docs/common-things.sh @@ -1,7 +1,4 @@ -#!/bin/bash - - - +# shellcheck disable=2148 # listing all useragent from your logs @@ -56,9 +53,9 @@ rm $chromefilename # measuring time in fish shell: -set -l then (gdate +%s%N); -sleep 0.5; -set -l andnow (gdate +%s%N); echo cool (math ( math $andnow - $then) / 1000 / 1000 ) +# set -l earlier (gdate +%s%N); +# sleep 0.5; +# set -l andnow (gdate +%s%N); echo cool (math ( math $andnow - $earlier) / 1000 / 1000 ) diff --git a/docs/upsampling images.sh b/docs/upsampling images.sh index 238887e89..c383411a7 100644 --- a/docs/upsampling images.sh +++ b/docs/upsampling images.sh @@ -1,3 +1,5 @@ +# shellcheck disable=2148 + # basic convert image-filename.png -resize 300% image-filename.3x-basic.png diff --git a/setup-a-new-machine.sh b/setup-a-new-machine.sh index bbc515f58..bf0a773c1 100755 --- a/setup-a-new-machine.sh +++ b/setup-a-new-machine.sh @@ -1,5 +1,6 @@ # copy paste this file in bit by bit. # don't run it. +# shellcheck disable=2148 echo "do not run this script in one go. hit ctrl-c NOW" read -n 1 diff --git a/setup-chromium.sh b/setup-chromium.sh index a95c5e810..32601c59c 100644 --- a/setup-chromium.sh +++ b/setup-chromium.sh @@ -2,6 +2,7 @@ ## Chromium hacking # improve perf of git inside of chromium checkout +# shellcheck disable=2148 # Read https://chromium.googlesource.com/chromium/src/+/HEAD/docs/mac_build_instructions.md#improving-performance-of-git-commands # ... and do it all. diff --git a/symlink-setup.sh b/symlink-setup.sh index 4c211fb12..1f3fd75ff 100755 --- a/symlink-setup.sh +++ b/symlink-setup.sh @@ -159,7 +159,7 @@ main() { local sourceFile="" local targetFile="" - for i in ${FILES_TO_SYMLINK[@]}; do + for i in "${FILES_TO_SYMLINK[@]}"; do sourceFile="$(pwd)/$i" targetFile="$HOME/$(printf "%s" "$i" | sed "s/.*\/\(.*\)/\1/g")" From 60ea5692aae1f2592d7a7f3c80434e850ae341af Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Sun, 2 Jun 2024 14:06:01 -0700 Subject: [PATCH 7/7] gemi tweaks --- fish/aliases.fish | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/fish/aliases.fish b/fish/aliases.fish index d56e09c3a..aa690369d 100644 --- a/fish/aliases.fish +++ b/fish/aliases.fish @@ -139,14 +139,26 @@ alias brew_update="brew -v update; brew upgrade --force-bottle --cleanup; brew c alias update_brew_npm_gem='brew_update; npm install npm -g; npm update -g; sudo gem update --system; sudo gem update --no-document' -abbr gemini "llm -m gemini-1.5-pro-latest" - function gemi # using https://github.com/simonw/llm-gemini and llm - if test -n "$argv[1]" - llm prompt -m gemini-1.5-pro-latest $argv[1] | deno run --allow-env --allow-read --allow-run bin/render-streaming-markdown.ts - else + # no args? chat. otherwise use prompt, and allow unquoted stuff to work too + # gemi + # gemi tell me a joke + # gemi "tell me a joke" + if test -z "$argv[1]" + # no markdown parsing here without some real fancy stuff. because you dont want to send to markdown renderer (glow) inbetween backticks, etc. llm chat --continue -m gemini-1.5-pro-latest + else + llm prompt -m gemini-1.5-pro-latest "$argv" && echo "⬇️… and now rendered…⬇️" && llm logs -r | glow + end +end + +function openai + # using llm. same dealio as above + if test -z "$argv[1]" + llm chat --continue -m gpt-4o + else + llm prompt -m gpt-4o "$argv" && echo "⬇️… and now rendered…⬇️" && llm logs -r | glow end end