修复空目录下 ls 函数报数组下标越界

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 <noreply@anthropic.com>
This commit is contained in:
FlintyLemming
2026-07-31 04:56:41 -07:00
parent 5ec2e7a9fb
commit 50688c76fd
+6
View File
@@ -111,6 +111,12 @@ function ls --description 'alias ls to eza with directory `.tldr` descriptions'
return return
end end
# 空目录直接返回:BSD seqmacOS)遇到 `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)) for i in (seq (count $lines))
set -l line $lines[$i] set -l line $lines[$i]