From cc8e81c12ebd466f3fd2b77fff244eddb1fb84cc Mon Sep 17 00:00:00 2001 From: mfyuu <83203852+mfyuu@users.noreply.github.com> Date: Wed, 25 Feb 2026 20:41:44 +0900 Subject: [PATCH 1/3] fix(shell): retain prefix during up-arrow history search (#2) fast-syntax-highlighting rewrites $LASTWIDGET, causing up-line-or-beginning-search to lose the original prefix on consecutive invocations. Replace it with a custom wrapper around the builtin .history-beginning-search-backward that: - tracks continuation via $BUFFER comparison instead of $LASTWIDGET - moves cursor to end-of-line after each match - clears stale POSTDISPLAY left by zsh-autosuggestions --- home/shell/zsh/lazy.zsh | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/home/shell/zsh/lazy.zsh b/home/shell/zsh/lazy.zsh index cda1bb3..f53ceda 100644 --- a/home/shell/zsh/lazy.zsh +++ b/home/shell/zsh/lazy.zsh @@ -6,11 +6,32 @@ function _backward-delete-char-clear() { zle -N _backward-delete-char-clear bindkey '^?' _backward-delete-char-clear -autoload -Uz up-line-or-beginning-search down-line-or-beginning-search -zle -N up-line-or-beginning-search -zle -N down-line-or-beginning-search -bindkey "^[[A" up-line-or-beginning-search -bindkey "^[[B" down-line-or-beginning-search +function _history-beginning-search-backward-end { + if [[ $BUFFER != "${_hbs_expected:-}" ]]; then + _hbs_prefix_len=$CURSOR + fi + CURSOR=$_hbs_prefix_len + zle .history-beginning-search-backward + CURSOR=$#BUFFER + _hbs_expected=$BUFFER + unset POSTDISPLAY +} +zle -N _history-beginning-search-backward-end + +function _history-beginning-search-forward-end { + if [[ $BUFFER != "${_hbs_expected:-}" ]]; then + _hbs_prefix_len=$CURSOR + fi + CURSOR=$_hbs_prefix_len + zle .history-beginning-search-forward + CURSOR=$#BUFFER + _hbs_expected=$BUFFER + unset POSTDISPLAY +} +zle -N _history-beginning-search-forward-end + +bindkey "^[[A" _history-beginning-search-backward-end +bindkey "^[[B" _history-beginning-search-forward-end # custom functions tp() { From e4438432029c42a9e70e72b423f1541041095b5d Mon Sep 17 00:00:00 2001 From: mfyuu <83203852+mfyuu@users.noreply.github.com> Date: Wed, 25 Feb 2026 23:09:29 +0900 Subject: [PATCH 2/3] feat(ci): add PR benchmark workflow with composite actions - extract common steps into reusable composite actions - create setup-bench-env action for Nix install and environment setup - create run-benchmark action for hyperfine execution - add benchmark-pr.yml to run benchmarks on pull requests - refactor benchmark.yml to use composite actions - remove redundant zsh warmup (hyperfine --warmup handles it) --- .github/actions/run-benchmark/action.yml | 30 ++++++++++ .github/actions/setup-bench-env/action.yml | 62 +++++++++++++++++++ .github/workflows/benchmark-pr.yml | 43 +++++++++++++ .github/workflows/benchmark.yml | 70 ++-------------------- 4 files changed, 140 insertions(+), 65 deletions(-) create mode 100644 .github/actions/run-benchmark/action.yml create mode 100644 .github/actions/setup-bench-env/action.yml create mode 100644 .github/workflows/benchmark-pr.yml diff --git a/.github/actions/run-benchmark/action.yml b/.github/actions/run-benchmark/action.yml new file mode 100644 index 0000000..8fb6048 --- /dev/null +++ b/.github/actions/run-benchmark/action.yml @@ -0,0 +1,30 @@ +name: Run Benchmark +description: Run zsh startup benchmark with hyperfine and convert results + +inputs: + hm_gen: + description: Path to the home-manager generation (for PATH setup) + required: true + +outputs: + result-path: + description: Path to the converted benchmark result JSON + value: benchmark-result.json + +runs: + using: composite + steps: + - name: Run benchmark + shell: bash + run: | + export PATH="${{ inputs.hm_gen }}/home-path/bin:$PATH" + + hyperfine \ + --warmup 10 \ + --runs 50 \ + --export-json bench-result.json \ + 'zsh -i -c exit' + + - name: Convert to benchmark format + shell: bash + run: bash .github/scripts/convert-hyperfine.sh bench-result.json benchmark-result.json diff --git a/.github/actions/setup-bench-env/action.yml b/.github/actions/setup-bench-env/action.yml new file mode 100644 index 0000000..425ca84 --- /dev/null +++ b/.github/actions/setup-bench-env/action.yml @@ -0,0 +1,62 @@ +name: Setup Benchmark Environment +description: Install Nix, build home-manager generation, and set up shell environment for benchmarking + +outputs: + hm_gen: + description: Path to the home-manager generation + value: ${{ steps.build.outputs.hm_gen }} + +runs: + using: composite + steps: + - name: Install Nix + uses: DeterminateSystems/determinate-nix-action@v3 + + - name: Build home-manager generation + id: build + shell: bash + run: | + HM_GEN=$(nix build --no-link --print-out-paths \ + '.#darwinConfigurations.M4Pro.config.home-manager.users.mfyuu.home.activationPackage') + echo "hm_gen=$HM_GEN" >> "$GITHUB_OUTPUT" + + - name: Set up shell environment + shell: bash + run: | + HM_GEN="${{ steps.build.outputs.hm_gen }}" + + # Replace macOS default /etc/ files to match nix-darwin environment. + # - /etc/zprofile: remove path_helper (slow PATH construction) + # - /etc/zshrc: remove compinit/promptinit (nix-darwin sets enableGlobalCompInit=false) + # - /etc/zshenv: keep Nix daemon setup for PATH + # See hosts/common/default.nix:19-23 + sudo sh -c ' + echo "" > /etc/zprofile + echo "" > /etc/zshrc + ' + + # Create /Users/mfyuu for HISTFILE (home-manager hardcodes home.homeDirectory) + sudo mkdir -p /Users/mfyuu + sudo chown "$(whoami)" /Users/mfyuu + + # Symlink user-level dotfiles + ln -sf "$HM_GEN/home-files/.zshrc" ~/.zshrc + ln -sf "$HM_GEN/home-files/.zshenv" ~/.zshenv + ln -sf "$HM_GEN/home-files/.zprofile" ~/.zprofile + + # Symlink .config directories + mkdir -p ~/.config + for item in "$HM_GEN/home-files/.config/"*; do + name=$(basename "$item") + rm -rf "$HOME/.config/$name" + ln -sf "$item" "$HOME/.config/$name" + done + + # Add home-manager binaries to PATH + export PATH="$HM_GEN/home-path/bin:$PATH" + + # Pre-populate sheldon cache (first run clones plugins via git) + mkdir -p ~/.cache/sheldon + sheldon lock + sheldon source > ~/.cache/sheldon/sheldon.zsh + readlink ~/.config/sheldon/plugins.toml > ~/.cache/sheldon/sheldon.zsh.lock diff --git a/.github/workflows/benchmark-pr.yml b/.github/workflows/benchmark-pr.yml new file mode 100644 index 0000000..2bf1b4f --- /dev/null +++ b/.github/workflows/benchmark-pr.yml @@ -0,0 +1,43 @@ +name: Zsh Startup Benchmark (PR) + +on: + pull_request: + branches: [main] + +concurrency: + group: benchmark-pr-${{ github.event.pull_request.number }} + cancel-in-progress: true + +permissions: + pull-requests: write + +jobs: + benchmark: + name: Zsh Startup Time + runs-on: macos-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v6 + + - uses: ./.github/actions/setup-bench-env + id: env + + - uses: ./.github/actions/run-benchmark + with: + hm_gen: ${{ steps.env.outputs.hm_gen }} + + - name: Comment benchmark result on PR + uses: benchmark-action/github-action-benchmark@v1 + with: + name: Zsh Startup Time + tool: customSmallerIsBetter + output-file-path: benchmark-result.json + benchmark-data-dir-path: . + github-token: ${{ secrets.GITHUB_TOKEN }} + auto-push: false + save-data-file: false + alert-threshold: "150%" + comment-on-alert: true + comment-always: true + fail-on-alert: true + summary-always: true diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index c43cfab..54de009 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -20,75 +20,15 @@ jobs: steps: - uses: actions/checkout@v6 - - name: Install Nix - uses: DeterminateSystems/determinate-nix-action@v3 - - - name: Build home-manager generation - id: build - run: | - HM_GEN=$(nix build --no-link --print-out-paths \ - '.#darwinConfigurations.M4Pro.config.home-manager.users.mfyuu.home.activationPackage') - echo "hm_gen=$HM_GEN" >> "$GITHUB_OUTPUT" - - - name: Set up shell environment - run: | - HM_GEN="${{ steps.build.outputs.hm_gen }}" - - # Replace macOS default /etc/ files to match nix-darwin environment. - # - /etc/zprofile: remove path_helper (slow PATH construction) - # - /etc/zshrc: remove compinit/promptinit (nix-darwin sets enableGlobalCompInit=false) - # - /etc/zshenv: keep Nix daemon setup for PATH - # See hosts/common/default.nix:19-23 - sudo sh -c ' - echo "" > /etc/zprofile - echo "" > /etc/zshrc - ' - - # Create /Users/mfyuu for HISTFILE (home-manager hardcodes home.homeDirectory) - sudo mkdir -p /Users/mfyuu - sudo chown "$(whoami)" /Users/mfyuu - - # Symlink user-level dotfiles - ln -sf "$HM_GEN/home-files/.zshrc" ~/.zshrc - ln -sf "$HM_GEN/home-files/.zshenv" ~/.zshenv - ln -sf "$HM_GEN/home-files/.zprofile" ~/.zprofile - - # Symlink .config directories - mkdir -p ~/.config - for item in "$HM_GEN/home-files/.config/"*; do - name=$(basename "$item") - rm -rf "$HOME/.config/$name" - ln -sf "$item" "$HOME/.config/$name" - done - - # Add home-manager binaries to PATH - export PATH="$HM_GEN/home-path/bin:$PATH" - - # Pre-populate sheldon cache (first run clones plugins via git) - mkdir -p ~/.cache/sheldon - sheldon lock - sheldon source > ~/.cache/sheldon/sheldon.zsh - readlink ~/.config/sheldon/plugins.toml > ~/.cache/sheldon/sheldon.zsh.lock - - # Warm up caches: cache_eval, zcompile (.zwc for sheldon.zsh) - zsh -i -c exit + - uses: ./.github/actions/setup-bench-env + id: env - name: Disable git commit signing run: git config --global commit.gpgsign false - - name: Run benchmark - run: | - HM_GEN="${{ steps.build.outputs.hm_gen }}" - export PATH="$HM_GEN/home-path/bin:$PATH" - - hyperfine \ - --warmup 10 \ - --runs 50 \ - --export-json bench-result.json \ - 'zsh -i -c exit' - - - name: Convert to benchmark format - run: bash .github/scripts/convert-hyperfine.sh bench-result.json benchmark-result.json + - uses: ./.github/actions/run-benchmark + with: + hm_gen: ${{ steps.env.outputs.hm_gen }} - name: Store benchmark result uses: benchmark-action/github-action-benchmark@v1 From 336d95011ce25a1912655d089c45937fa401a2b0 Mon Sep 17 00:00:00 2001 From: mfyuu <83203852+mfyuu@users.noreply.github.com> Date: Wed, 25 Feb 2026 23:23:16 +0900 Subject: [PATCH 3/3] fix(ci): disable git commit signing in PR benchmark workflow - benchmark-action internally commits to gh-pages even with save-data-file: false, causing failure due to missing 1Password SSH signer in CI --- .github/workflows/benchmark-pr.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/benchmark-pr.yml b/.github/workflows/benchmark-pr.yml index 2bf1b4f..00e566e 100644 --- a/.github/workflows/benchmark-pr.yml +++ b/.github/workflows/benchmark-pr.yml @@ -22,6 +22,9 @@ jobs: - uses: ./.github/actions/setup-bench-env id: env + - name: Disable git commit signing + run: git config --global commit.gpgsign false + - uses: ./.github/actions/run-benchmark with: hm_gen: ${{ steps.env.outputs.hm_gen }}