Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Jun 7, 2024
2 parents 247dca6 + 60ea569 commit 03366f4
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 89 deletions.
81 changes: 44 additions & 37 deletions .iterm2_shell_integration.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
54 changes: 54 additions & 0 deletions bin/render-streaming-markdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// usage:
// cat README.md | deno run --allow-env --allow-read --allow-run bin/render-streaming-markdown.ts
//

import $ from 'jsr:@david/[email protected]'
// todo: replace dax with this:
// import { exec } from 'https://deno.land/std/process.mod.ts';
import { writeAllSync } from 'https://deno.land/[email protected]/streams/mod.ts';

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) {
// show immediately, but meanwhile…
writeAllSync(Deno.stdout, chunk);
// Collect it.
inputBuffer += decoder.decode(chunk);
}

// 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));
// }
2 changes: 1 addition & 1 deletion brew.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash

# Install command-line tools using Homebrew

Expand Down
41 changes: 0 additions & 41 deletions docs/clearing-disk-space.sh

This file was deleted.

11 changes: 4 additions & 7 deletions docs/common-things.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/bin/bash



# shellcheck disable=2148


# listing all useragent from your logs
Expand Down Expand Up @@ -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 )



Expand Down
2 changes: 2 additions & 0 deletions docs/upsampling images.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# shellcheck disable=2148

# basic
convert image-filename.png -resize 300% image-filename.3x-basic.png

Expand Down
21 changes: 21 additions & 0 deletions fish/aliases.fish
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,28 @@ 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'


function gemi
# using https://github.com/simonw/llm-gemini and llm
# 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

# project-specific shorthands

Expand Down
2 changes: 1 addition & 1 deletion fish/config.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions fish/functions/fish_prompt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions setup-a-new-machine.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions setup-chromium.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion symlink-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand Down

0 comments on commit 03366f4

Please sign in to comment.