From 50688c76fd8df1cf1cdae3b06fd5d3756b678a85 Mon Sep 17 00:00:00 2001 From: FlintyLemming Date: Fri, 31 Jul 2026 04:56:41 -0700 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A9=BA=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=B8=8B=20ls=20=E5=87=BD=E6=95=B0=E6=8A=A5=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E4=B8=8B=E6=A0=87=E8=B6=8A=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit macOS 自带的 BSD seq 在 first > last 时默认步长为 -1,所以空目录下 `seq (count $lines)` 即 `seq 0` 会输出 "1 0" 而非空,导致循环取到 $lines[0] 报 "array indices start at 1, not 0"(GNU seq 无此问题)。 循环前加空数组短路返回。 Co-Authored-By: Claude --- fish/add-on.fish | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fish/add-on.fish b/fish/add-on.fish index afc4ea1..f366f59 100644 --- a/fish/add-on.fish +++ b/fish/add-on.fish @@ -111,6 +111,12 @@ function ls --description 'alias ls to eza with directory `.tldr` descriptions' return end + # 空目录直接返回:BSD seq(macOS)遇到 `seq 0` 会倒数输出 "1 0", + # 导致下面用 $lines[0] 取值时报 "array indices start at 1" + if test (count $lines) -eq 0 + return + end + # 双路循环渲染 for i in (seq (count $lines)) set -l line $lines[$i]