修复空目录下 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:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user